init script for apcupsd
Earlier I had blogged about running an APC UPS monitoring software in linux, called apcupsd. For those who wanted to run apcupsd (A daemon that monitors any APC UPSes connected to your system), you can use a script which I created for myself. Here it is. Create a file in /etc/init.d and name it apcupsd and copy the below script into it. I’ve created this for fedora 9.( Make sure you don’t have a apcupsd~ file created by your editor.) Once you’ve created the file, just execute a command such as ‘chkconfig –levels 12345 apcupsd on’ to enable the apcupsd services at all times and you should see apcupsd running automatically upon next boot!
#!/bin/bash
#
# /etc/rc.d/init.d/apcupsd
#
# Starts the "apcupsd" daemon
#
# chkconfig: - 47 24
#
# description: Runs the apc ups daemon.
# processname: apcupsd
# Source function library.
. /etc/init.d/functions
# pull in sysconfig settings
RETVAL=0
prog="apcupsd"
APCUPSD=/sbin/apcupsd
LOCK_FILE=/var/lock/apcupsd
start() {
# Check if apcupsd is already running
echo -n $"Starting $prog: "
$APCUPSD && success || failure
RETVAL=$?
[ "$RETVAL" = 0 ] && touch $LOCK_FILE
echo
}
stop() {
echo -n $"Stopping $prog: "
if [ -n "`pidfileofproc $APCUPSD`" ] ; then
killproc $APCUPSD
else
failure $"Stopping $prog"
fi
RETVAL=$?
[ "$RETVAL" = 0 ] && rm -f $LOCK_FILE
echo
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
if [ -n "`pidfileofproc $APCUPSD`" ]; then
killproc $APCUPSD -HUP
else
failure $"Reloading $prog"
fi
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
condrestart)
if [ -f $LOCK_FILE ]; then
if [ "$RETVAL" = 0 ]; then
stop
sleep 3
start
fi
fi
;;
status)
status $APCUPSD
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=3
esac
exit $RETVAL



