apcupsd on RHEL5 / CentOS5

While the current Smart-UPS (aka SMT) range of UPS from APC has much fewer variables exposed in a way that is useful for fancy apcupsd usage (you’ll find apcupsd in EPEL), they are still amply sufficient for home use. Basically, the UPS gives an estimated time left at current load and the remaining battery level. At home these are anyway the only two readings I want to trigger scripts on.

##On the machine that has a USB connection to the UPS Connect the UPS via USB to your server. Then install apcupsd

# yum install apcupsd

and adjust /etc/apcupsd/apcupsd.conf. I changed the following from defaults to be a bit more conservative;


Be sure to set an email address you read often in the scripts that are run on events (e.g.: /etc/apcupsd/onbattery ), ideally using an email to SMS gateway. For USB based SMT series, no further changes are necessary as that type of connection is the default.

For the next step to work, you’ll want to allow access to the daemon through the local firewall. Something along the lines of

# iptables -I defaults 1 -i eth0 -p tcp -m tcp --dport 3551 -j ACCEPT 

Or use system-config-firewall to allow 3551 TCP.

##On machines that get power from the same UPS and can reach the main box over the network Install and configure /etc/apcupsd/apcupsd.conf as before, but this time point it at a machine called server. Additionally, I shut down most of these boxes earlier.

DEVICE server:3551

And you may want to take more drastic action in the /etc/acpupsd/commfailure script if you want to react to network outages.

All the other options are sane if all you want is your machines to shut down cleanly before the UPS runs fully out of juice.

Unimportant things (e.g. the WLAN AP) get plugged into the secondary ports (caveat the SMT750I does not have these) and the behaviour of these ports configured on the UPS front panel.

Mind bug 661304, as RHEL5 is still using SysV init, my /etc/init.d/halt reads near the bottom:

# Now halt or reboot.
echo $"$message"
if [ -f /fastboot ]; then
 echo $"On the next boot fsck will be skipped."
elif [ -f /forcefsck ]; then
 echo $"On the next boot fsck will be forced."

if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
        . /etc/sysconfig/ups
        if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
                /sbin/upsdrvctl shutdown
        elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
                $MODEL $OPTIONS_HALT -k $DEVICE

# First, try kexec. If that fails, fall back to rebooting the old way.
[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null