#!/bin/bash
#
# chkconfig: 345 95 05
# description: WULFD watches the status of the slave nodes on the cluster
#              and keeps them configured properly and available to cluster
#              users.
# processname: wulfd
# pidfile: /var/run/wulfd.pid

if [ ! -f "/etc/sysconfig/wulfd" ]; then
   exit
fi

# source function library
. /etc/init.d/functions
. /etc/sysconfig/wulfd

RETVAL=0

start() {
   if [ -x /usr/sbin/wulfd ]; then
      gprintf "Starting wulfd: "
      if [ -f /var/run/wulfd.pid ]; then
         status wulfd
         exit 1
      else
         daemon /usr/sbin/wulfd -m $ADMIN_MASTER $WULFD_OPTIONS </dev/null
         RETVAL=$?
         echo
      fi
   fi
}

stop() {
   if [ -f /var/lock/subsys/wulfd ]; then
      gprintf "Shutting down wulfd: "
      killproc wulfd
      RETVAL=$?
      echo
   fi
   test -f /var/run/wwnodestatus 	&& rm -f /var/run/wwnodestatus
   test -f /var/lock/subsys/wulfd 	&& rm -f /var/lock/subsys/wulfd
}

stats() {
   if [ -x /usr/sbin/wulfd ]; then
      status wulfd
      RETVAL=0
   fi
}

case "$1" in
  start)
   start
   ;;
  stop)
   stop
   ;;
  restart)
   stop
   start
   RETVAL=0
   ;;
#  reload)
 #  reload
 #  ;;
  status)
   stats
   ;;
  *)
   gprintf "Usage: %s {start|stop|restart|status}\n" "$0"
   exit 1
esac

exit $RETVAL
