#!/bin/sh
#
# upsmon	NUT daemon monitoring tool
#
# chkconfig:	2345 10 90
#
# description:	upsmon talks to upsd and notifies of ups status changes, \
#		also shutting systems down if required.
# processname:	upsmon
# config:	/etc/ups/

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

# Get config.
[ -f /etc/sysconfig/upsmon ] && . /etc/sysconfig/upsmon

RETVAL=0
# See how we are called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/upsmon ]; then
		msg_starting "UPSmon"
		daemon upsmon $PROGRAM_ARGS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/upsmon
	else
		msg_already_running "UPSmon"
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/upsmon ]; then
		msg_stopping "UPSmon"
		killproc upsmon
		rm -f /var/lock/subsys/upsmon
	else
		msg_not_running "UPSmon"
	fi
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  status)
	status upsmon
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
