#!/bin/bash
#
# fence_sanlockd - daemon for fence_sanlock agent
#
# chkconfig: 345 98 03
# description: starts and stops fence_sanlockd
#


### BEGIN INIT INFO
# Provides: fence_sanlockd
# Required-Start: $time $syslog wdmd sanlock
# Required-Stop: $syslog
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts and stops fence_sanlockd
# Description: starts and stops fence_sanlockd
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

SERVICE=fence_sanlockd
AGENT=fence_sanlock
PIDFILE=/run/$SERVICE/$SERVICE.pid
FIFOFILE=/run/$SERVICE/$SERVICE.fifo
LOCKFILE=/run/lock/subsys/$SERVICE

FENCESANLOCKDOPTS="-w"

# Source config.
SourceIfNotEmpty /etc/sysconfig/$SERVICE

RETVAL=0

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

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

restart() {
	stop
	start
}

reload() {
	restart
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- $SERVICE
		RETVAL=$?
		;;
	restart)
		restart
		;;
	reload)
		reload
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
		RETVAL=1
esac

exit $RETVAL

