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

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

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

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

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

rhstatus() {
	status adacsd
}	

restart() {
  	stop
	start
}	

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

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