#! /bin/sh
#set -x
#
# Author: Martin Fuerstenau <martin.fuerstenau@ops.de>
#
# /etc/init.d/srcd
# 
# description: srcd	ICP Vortec controller monitoring daemon
#
# chkconfig: 345 99 01
# processname:	/usr/sbin/srcd      
# pidfile:	/var/run/srcd.pid

SRCD_BIN=/usr/sbin/srcd
SRCD_PID=/var/run/srcd.pid
SRCD_CONFIG=/etc/srcd.conf

# Check for missing binaries (stale symlinks should not happen)

test -x $SRCD_BIN || exit 5

# Check for existence of needed config file and read it

test -r $SRCD_CONFIG || exit 6

if [ ! -x $SRCD_BIN ] ; then
	echo -n "srcd raid controller monitoring daemon not installed ! "
	exit 5
fi


# Source LSB init functions
# providing start_daemon, killproc, pidofproc, 
# log_success_msg, log_failure_msg and log_warning_msg.

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


LOCKFILE=/var/lock/subsys/srcd

start() {
	if [ ! -f $LOCKFILE ]; then
	   echo -n "Starting srcd "

           daemon $SRCD_BIN -l 3 -f $SRCD_CONFIG
	   RETVAL=$?
	   [ $RETVAL -eq 0 ] && touch $LOCKFILE
	   echo
	fi
	return $RETVAL
	}

stop() {
       echo -n "Shutting down srcd "

       killproc $SRCD_BIN
       RETVAL=$?
       [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
       echo
       return $RETVAL
       }
       
case "$1" in
    start) 
          start
	  ;;
    stop)
          stop
	  ;;
    restart)
	  stop
	  start
	  ;;
    status)
          status srcd
	  RETVAL=$?
	  ;;
    *)
	echo $"Usage: $0 {start|stop|restart|status}"
	RETVAL=1
esac
