#!/bin/sh
#
# cpqarrayd    Start/Stop Compaq Array monitor
#
# chkconfig: 345 15 90
# description: The cpqarrayd monitors the status of Compaq Raid Arrays, \
#              and reports via syslog or traps
# processname: cpqarrayd

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

CPQ_PARAMS=""

# Get config.
if [ -f /etc/sysconfig/cpqarrayd ]; then
	. /etc/sysconfig/cpqarrayd
fi

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/cpqarrayd ]; then
		msg_starting cpqarrayd
		for host in $TRAP_DESTINATIONS; do
			CPQ_PARAMS="$CPQ_PARAMS -t $host"
		done
		daemon cpqarrayd $CPQ_PARAMS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/cpqarrayd
	else
		msg_already_running cpqarrayd
	fi
}

stop() {
	if [ -f /var/lock/subsys/cpqarrayd ]; then
		# Stop daemons.
		msg_stopping cpqarrayd
		killproc cpqarrayd
		rm -f /var/lock/subsys/cpqarrayd
	else
		msg_not_running cpqarrayd
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/cpqarrayd ]; then
		stop
		start
	else
		msg_not_running cpqarrayd
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
start)
	start
	;;
stop)
	stop
	;;
restart)
	stop
	start
	;;
try-restart)
	condrestart 0
	;;
force-reload)
	condrestart 7
	;;
status)
	status cpqarrayd
	RETVAL=$?
	;;
*)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
