Apcupsd PowerChute in Linux
Jan.23, 2010, under Sysadmin
If you have ever had to install a PowerChute agent on a Linux machine, you have probably come across the problem that a Java based GUI is required to configure it.Many Linux servers don’t have a GUI and you may not want to have to worry about setting up Java. If this is the case, we can turn to apcupsd to help with our problem. The example commands here work on RHEL5, if you have a different distribution your files may be in different places.
Apcupsd is an open source ups agent designed to work with APC products. It is fairly simple to set up, and there is a ton of documentation on the website. The first thing you will want to do is download the rpm, and then install it on your server.
Since this is a PowerChute setup I will work under the assumption that you have multiple machines running off of one UPS. If this is the case you will want to alter the default install slightly. By default the software is configured to shut down your UPS once the server has finished powering down, which we definitely don’t want if our UPS is powering multiple systems. To make these changes, check for lines labeled apcupsd in your system halt file and remove all the lines you find:
cat /etc/rc.d/init.d/halt | grep apcupsd
Once this is done we need to tell apcupsd what kind of UPS it is talking to. To do this, edit <tt>/etc/apcupsd/apcupsd.conf</tt> and make sure the following configuration is set up. Note that IP is your UPS IP, the username is usually apc, and the passphrase is your agent passphrase, not your administration password for the web interface.
UPSCABLE ether
UPSTYPE pcnet
LOCKFILE /var/lock
DEVICE ipaddr:user:passphrase
UPSCLASS standalone
UPSMODE disable
Once this is done, ensure apcupsd is set up to run at startup, and start the service.
chkconfig apcupsd on
service apcupsd restart
At this point check in /etc/apcupsd/apcupsd.events to ensure that there are no errors. If you get a message saying communications with the UPS have been lost, you either have a configuration issue or need to update your firewall rules similar to the following:
-A RH-Firewall-1-INPUT -p udp --dport 3052 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3052 -j ACCEPT
At this point you are ready to test a power fail and ensure that the system powers off gracefully.
A few other points to bear in mind, the PowerChute support in apcupsd is unfortunately not as mature as the official product, so you don’t get a web interface on your server to check its status. Options for custom shutdown scripts etc are still available and can be found in the official documentation. It is also worth mentioning that if for whatever reason you would still prefer to use the official agent, you can work around the GUI requirement by installing the agent on another server which does have a GUI, and then copying the files across.