#!/bin/bash
#
# qdiskd quorum disk daemon
#
# chkconfig: - 22 78
# description: Starts and stops the quorum disk daemon

### BEGIN INIT INFO
# Provides: 		qdiskd
# Required-Start:	cman
# Required-Stop:	cman
# Default-Start:	2 3 5
# Default-Stop:
# Short-Description:	start/stop quorum disk daemon
# Description:		start/stop quorum disk daemon
### END INIT INFO

. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster

LOCK_FILE="/var/lock/subsys/qdiskd"
QDISKD="/usr/sbin/qdiskd"
retries=0

# See how we were called.
case "$1" in
  start)
	echo -n "Starting the Quorum Disk Daemon:"

	startproc $QDISKD
	rc_status	
	;;

  stop)
	echo -n "Stopping the Quorum Disk Daemon:"
	killproc $QDISKD
	while [ -n "`pidof qdiskd`" ] && [ $retries -lt 5 ]; do
		sleep 1
		killproc $QDISKD
		((retries++))
	done
	if [ -z "`pidof qdiskd`" ]; then
		rc_status
		rm -f $LOCK_FILE
	else
		rc_failed
	fi
	;;

  restart|reload)
	$0 stop || exit $?
	$0 start 
	;;

  status)
	checkproc $QDISKD
	rc_status
	;;

  *)
	echo $"Usage: $0 {start|stop|reload|restart|status}"
	;;
esac

rc_exit
