The APC Smart-UPS series of UPS devices allows you to power servers and switches when there is a power failure in the grid. When the UPS is running on batteries, you want your servers to be notified and properly shutdown. This article shows how you can accomplish that. We use the APC Smart-UPS X2200, with the UPS Network Management Card 2 type AP9630, with a server running CentOS 6.7. Different APC UPS devices with such a network management card and other operating systems may work as well.
We start with the configuration of the UPS. Use the buttons on the display to enable the advanced menu and then configure the network management card. Use this to set an IP address, either manual or automatic with DHCP. Then use a web browser to connect to the UPS. The default username and password are apc. In the menu select ‘Configuration’ and then ‘PowerChute Clients’.
In the resulting page click the ‘Add Client’ button, fill in the IP address of your server and click ‘Apply’.
The configuration of the UPS is now done, so let’s continue with the server. First, install the apcupsd software:
yum install apcupsd
The configuration is changed by editing the /etc/apcupsd/apcupsd.conf file:
UPSNAME alice UPSCABLE ether UPSTYPE pcnet DEVICE 10.20.30.40:apc:admin user phrase
Replace the UPSNAME setting with the name of your choice. This is used in logs and on the console for broadcast messages about the UPS. Change the DEVICE setting to contain the IP address of your UPS. The last two bits of the DEVICE setting contain the username (default apc) with the passphrase (default admin user phrase).
Make sure that UDP port 3052 on the server is reachable from the UPS. If you don’t care much about security, the easiest way to achieve this is:
iptables --flush iptables --table nat --flush iptables --delete-chain iptables --table nat --delete-chain /etc/init.d/iptables save
Now start the service and make sure it also starts when the system is booted:
service apcupsd start chkconfig apcupsd on
If we test the setup by unplugging the UPS and then plugging it back in, the following messages appear on the console:
Broadcast message from root@upstest (Thu Nov 5 14:50:53 2015): Power failure on UPS alice. Running on batteries. Broadcast message from root@upstest (Thu Nov 5 14:51:01 2015): Power has returned on UPS alice...
The log file of apcupsd in /var/log/apcupsd.events then contains:
2015-11-05 14:43:27 +0100 apcupsd 3.14.12 (29 March 2014) redhat startup succeeded 2015-11-05 14:50:47 +0100 Power failure. 2015-11-05 14:50:53 +0100 Running on UPS batteries. 2015-11-05 14:51:01 +0100 Mains returned. No longer on UPS batteries. 2015-11-05 14:51:01 +0100 Power is back. UPS running on mains.
If we set the TIMEOUT value in /etc/apcupsd/apcupsd.conf to e.g. 45 seconds and unplug the UPS longer than that, the output on the console shows this:
Broadcast message from root@upstest (Thu Nov 5 14:59:57 2015): Power failure on UPS alice. Running on batteries. Broadcast message from root@upstest (Thu Nov 5 15:00:43 2015): UPS alice initiated Shutdown Sequence Broadcast message from root@upstest (Thu Nov 5 15:00:43 2015): Battery time limit exceeded on UPS alice. Doing shutdown. Broadcast message from jansipke@upstest (unknown) at 15:00 ... The system is going down for halt NOW! apcupsd UPS alice initiated shutdown
The apcaccess command allows you to check certain values of the UPS from the server, e.g.:
# apcaccess -p BCHARGE 100.0 Percent # apcaccess -p LOADPCT 78.5 Percent
Running the apcaccess command without the -b parameter shows all values.