#!/bin/sh
#
# wdmd - watchdog multiplexing daemon
#
# chkconfig: 2345 97 03
# description: starts and stops wdmd daemon
#


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

. /etc/rc.d/init.d/functions

prog="wdmd"
pidfile="/var/run/$prog/$prog.pid"
exec="/usr/sbin/$prog"

WDMDGROUP="sanlock"
WDMDOPTS="-G $WDMDGROUP"

[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/wdmd ]; then
		msg_already_running "wdmd"
		return
	fi
	msg_starting "wdmd"
	daemon $prog $WDMDOPTS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/wdmd
}

stop() {
	if [ ! -f /var/lock/subsys/wdmd ]; then
		msg_not_running "wdmd"
		return
	fi
	killproc --pidfile $pidfile $prog
	rm -f /var/lock/subsys/wdmd
}

condrestart() {
	if [ ! -f /var/lock/subsys/wdmd ]; then
		msg_not_running "wdmd"
		RETVAL=$1
		return
	fi
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	try-restart)
		condrestart 0
		;;
	force-reload)
		condrestart 7
		;;
	status)
		status --pidfile $pidfile wdmd
		;;
	*)
		msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
		exit 3
esac
exit $RETVAL
