#!/bin/sh # Syn-3 apc control file. (C)DatuX # Using original apccontrol script as a guideline. APCPID=/var/run/apcupsd.pid APCUPSD=/sbin/apcupsd SHUTDOWN=/sbin/shutdown WALL=wall # Call syn3-apccheck status poller. # We dont use the events below, because events like commok could overwrite more imporant things like onbattery. syn3-apccheck &>/dev/null # Do default operations (from original apccontrol file) case "$1" in killpower) echo "Apccontrol doing: ${APCUPSD} --killpower on UPS ${2}" sleep 10 ${APCUPSD} --killpower echo "Apccontrol has done: ${APCUPSD} --killpower on UPS ${2}" | ${WALL} ;; commfailure) #NO: this is annoying if you dont have an UPS #echo "Warning communications lost with UPS ${2}" | ${WALL} ;; commok) echo "Communications restored with UPS ${2}" | ${WALL} ;; # # powerout, onbattery, offbattery, mainsback events occur # in that order. # powerout) ;; onbattery) echo "Power failure on UPS ${2}. Running on batteries." | ${WALL} ;; offbattery) echo "Power has returned on UPS ${2}..." | ${WALL} ;; mainsback) if [ -f /etc/powerfail ] ; then echo "Continuing with shutdown." | ${WALL} fi ;; failing) echo "Battery power exhaused on UPS ${2}. Doing shutdown." | ${WALL} ;; timeout) echo "Battery time limit exceeded on UPS ${2}. Doing shutdown." | ${WALL} ;; loadlimit) echo "Remaining battery charge below limit on UPS ${2}. Doing shutdown." | ${WALL} ;; runlimit) echo "Remaining battery runtime below limit on UPS ${2}. Doing shutdown." | ${WALL} ;; doreboot) echo "UPS ${2} initiating Reboot Sequence" | ${WALL} ${SHUTDOWN} -r now "apcupsd UPS ${2} initiated reboot" ;; doshutdown) echo "UPS ${2} initiated Shutdown Sequence" | ${WALL} ${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown" ;; annoyme) echo "Power problems with UPS ${2}. Please logoff." | ${WALL} ;; emergency) echo "Emergency Shutdown. Possible battery failure on UPS ${2}." | ${WALL} ;; changeme) echo "Emergency! Batteries have failed on UPS ${2}. Change them NOW" | ${WALL} ;; remotedown) echo "Remote Shutdown. Beginning Shutdown Sequence." | ${WALL} ;; startselftest) ;; endselftest) ;; battdetach) ;; battattach) ;; *) echo "Usage: ${0##*/} command" echo " warning: this script is intended to be launched by" echo " apcupsd and should never be launched by users." exit 1 ;; esac