#!/bin/bash
#
# sanlock - SAN-based lock manager
#
# chkconfig: 345 97 03
# description: starts and stops sanlock daemon
#


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

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

SERVICE=sanlock
PIDFILE=/var/run/$SERVICE/$SERVICE.pid
LOCKFILE=/var/lock/subsys/$SERVICE

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

RETVAL=0


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

stop() {
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user sanlock -- $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 sanlock -- $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
