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

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

CPQ_PARAMS=""
SourceIfNotEmpty /etc/sysconfig/cpqarrayd

PIDFILE=/var/run/cpqarrayd.pid
LOCKFILE=/var/lock/subsys/cpqarrayd
RETVAL=0

start()
{
	for host in $TRAP_DESTINATIONS; do
		CPQ_PARAMS="$CPQ_PARAMS -t $host"
	done
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- cpqarrayd $CPQ_PARAMS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- cpqarrayd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload|restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condreload|condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- cpqarrayd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
