#! /bin/sh # # apcupsd This shell script takes care of starting and stopping # the apcupsd UPS monitoring daemon. # # chkconfig: 2345 60 99 # description: apcupsd monitors power and takes action if necessary # ### BEGIN INIT INFO # Provides: apcupsd # Required-Start: $network $syslog # Required-Stop: $network $syslog # Default-Start: 2 3 5 # Default-Stop: # Description: Start the apcupsd daemon ### END INIT INFO APCPID=/var/run/apcupsd.pid # Source function libarary . /etc/rc.d/init.d/functions if [ ! -x /sbin/apcupsd -o ! -r /etc/apcupsd/apcupsd.conf ]; then exit 0 fi case "$1" in start) rm -f /etc/apcupsd/powerfail rm -f /etc/nologin # check for stale lockfiles LOCKDIR=`grep "^LOCKFILE" /etc/apcupsd/apcupsd.conf | awk '{ print $2}'` DEVICE=`grep "^DEVICE" /etc/apcupsd/apcupsd.conf | awk '{ print $2 }' | sed -e 's@/dev/@@g'` if [ -z "${DEVICE}" ]; then DEVICE=usb fi LOCKFILE="${LOCKDIR}/LCK..${DEVICE}" if [ -f $LOCKFILE ]; then PID=`cat $LOCKFILE | awk '{ printf("%d",$1) }'` else PID="" fi PIDREAL=`ps -e | awk '{print $1}' | grep "${PID}"` if [ ! -z "$PID" -a ! "$PID" = "$PIDREAL" ]; then gprintf "Stale lockfile, removing %s\n" "$LOCKFILE" if [ -f $LOCKFILE ]; then rm -f $LOCKFILE fi fi gprintf "Starting UPS monitoring:" /sbin/apcupsd -f /etc/apcupsd/apcupsd.conf && success || failure echo touch /var/lock/subsys/apcupsd ;; stop) gprintf "Shutting down UPS monitoring:" killproc apcupsd echo rm -f $APCPID rm -f /var/lock/subsys/apcupsd ;; restart|reload) $0 stop sleep 15 $0 start ;; status) /sbin/apcaccess status ;; *) gprintf "Usage: %s {start|stop|restart|reload|status}\n" "$0" exit 1 ;; esac exit 0