Storage

Using apcupsd to monitor a UPS

In the case of an extended power loss you need to set up the UPS device to trigger a clean shutdown before the battery drains. This tip tells you about the apcupsd monitoring tool in Linux.

Most server systems, regardless of what OS they are running, are connected to a UPS to ensure uptime in the event of power fluctuations, brief power outages, brown-outs, etc. Using a UPS is a great way to ensure data safety by preventing the machine from turning off immediately if the power goes out. However, in an extended power outage—when the downtime exceeds the capacity of the UPS battery—unless you have a system in place to monitor the status of the UPS, all that is being done is delaying the amount of time it takes for the system to halt.

A tool such as apcupsd, from http://sourceforge.net/projects/apcupsd/, can be used to monitor the status of the UPS and trigger a shutdown event prior to the battery being drained. This allows the system to shut down clean in the event of an extended power loss.

Most Linux distributions come with apcupsd and if not, building it from source is as trivial as building most other software from source. Keep in mind that apcupsd only works with APC-brand UPS devices—both serial- and USB-based. To determine if the system recognizes your USB-based UPS, you can check the USB device table by executing:

<code>
# cat /proc/bus/usb/devices
</code>

By examining this list, you should see the APC USB listed when it is connected. You will also need to modify the configuration file, /etc/apcupsd/apcupsd.conf in most cases, and tell it the type of UPS you have with the UPSNAME, UPSCABLE, and UPSTYPE directives. The configuration file is well commented and you can define how much battery power must remain before initiating the shutdown, etc. A number of scripts are included in the /etc/apcupsd/ directory that control various aspects of what apcupsd does when it detects power loss, power return, etc.

Having a UPS is a good idea no matter what type of system you are running, but setting up the UPS for automated shutdowns will go a long way in preventing data loss or corruption due to unexpected power loss.

Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

0 comments

Editor's Picks