#!/bin/sh
#
# smupsd	The APC Smart-UPS monitoring daemon
#
# Author:       David E. Myers <dem@skyline.rtp.nc.us>
#
# chkconfig: 12345 35 95
# description: Starts the smupsd daemon to monitor an APC Smart-UPS.

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

[ -x /usr/sbin/smupsd ] || exit 0

LOGFILE=/var/log/smupsd

# See how we were called.
case "$1" in
  start)
	echo -n "Starting Smart-UPS monitoring: "
	daemon smupsd -l ${LOGFILE} /dev/ups
	echo
	touch /var/lock/subsys/smupsd
	;;
  stop)
	echo -n "Shutting down Smart-UPS monitoring: "
	pid=`pidofproc smupsd`
	if [ "$pid" != "" ] ; then
		kill -TERM $pid 2> /dev/null
		# MUST pause here to give the daemon enough
		# time to schedule a UPS shutdown, if necessary.
		sleep 3
		echo -n "smupsd"
	fi

	echo
	rm -f /var/lock/subsys/smupsd
	;;
  *)
	echo "Usage: smupsd {start|stop}"
	exit 1
esac

exit 0

