#! /bin/bash
#
# hdacsd     Start/Stop the hdacsd daemon
#
# chkconfig: 345 90 60
# description: DaCS services for the Cell Broadband Engine (TM) blade
#
# processname: hdacsd
# config: /etc/dacsd.conf
# pidfile: /var/run/hdacsd.pid

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

# Source configuration file
. /etc/dacsd.conf
 
# See how we were called.
  
prog="hdacsd"

start() {
	echo -n $"Starting $prog: "	
        if [ -e /var/lock/subsys/hdacsd ]; then
	    if [ -e /var/run/hdacsd.pid ] && [ -e /proc/`cat /var/run/hdacsd.pid` ]; then
		echo -n $"cannot start hdacsd: hdacsd is already running.";
		failure $"cannot start hdacsd: hdacsd already running.";
		echo
		return 1
	    fi
	fi
	daemon /usr/sbin/hdacsd $HDACSD_ARGS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/hdacsd;
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
        if [ ! -e /var/lock/subsys/hdacsd ]; then
	    echo -n $"cannot stop hdacsd: hdacsd is not running."
	    failure $"cannot stop hdacsd: hdacsd is not running."
	    echo
	    return 1;
	fi
	killproc hdacsd
	RETVAL=$?
	echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/hdacsd;
	return $RETVAL
}	

rhstatus() {
	status hdacsd
}	

restart() {
  	stop
	start
}	

reload() {
	echo -n $"Reloading hdacsd daemon configuration: "
	killproc hdacsd -HUP
	RETVAL=$?
	echo
	return $RETVAL
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/hdacsd ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
esac
