#!/bin/bash

# Authors:
#  Andrew Beekhof <abeekhof@redhat.com>
#
# License: Revised BSD

# chkconfig: - 99 01
# description: Pacemaker Cluster Manager
# processname: pacemaker_remoted
#
### BEGIN INIT INFO
# Provides:		pacemaker_remote
# Required-Start:	$network $remote_fs
# Should-Start:		$syslog
# Required-Stop:	$network $remote_fs
# Default-Start:        3 4 5
# Default-Stop:         0 1 2 6
# Short-Description:	Starts and stops the Pacemaker remote agent for non-cluster nodes.
# Description:		Starts and stops the Pacemaker remote agent for non-cluster nodes
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

desc="Pacemaker Remote Agent"
prog="pacemaker_remoted"

SourceIfNotEmpty /etc/sysconfig/pacemaker_remote
LOCKFILE="/var/lock/subsys/$prog"
PIDFILE="/var/run/$prog.pid"
RETVAL=0

start()
{
	start_daemon --make-pidfile --background --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- $prog
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- $prog
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}



case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	status)
		status --expect-user root -- $prog
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|reload|condrestart|condstop|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
