For the past few weeks, I've been having too many brownouts at home. I decided it was time to get a UPS because I was getting tired of my Linux box and my file server shutting down all the time!
So a little bit of research brought me to the APC BX1300LCD. I found it on sale at Bureau en Gros for $169 (and it's back up to $229 now!) and brought it home. Taking it out of the box it sounded like something was rattling around inside the case but I decided to connect the batteries and plug it in anyways. Well, 15 minutes later the unit died and I had to open up an RMA with APC to replace the unit.
So after all that the new unit finally arrives, a refurbished unit, which doesn't bother me too much since the batteries are newer in the refurbed one than the one I bought and it has probably been tested better so.. whatever, it works that's what's important!
However, when they sent me the return packing slip by Canada Post they neglected to put enough postage on the envelope and now I'm left with a postage due in my mailbox for the return packing slip!
Anyway, let's get onto APCUPSD...
First off of course, we need to compile our USB drivers etc for linux. I used the Gentoo APCUPSD guide for this (http://en.gentoo-wiki.com/wiki/Apcupsd) for all the USB config and installing the daemon, but the config I played around with myself.
Here's what you'll want to change in your /etc/apcupsd/apcupsd.conf:
UPSNAME
UPSCABLE usb
UPSTYPE usb
ONBATTERYDELAY
BATTERYLEVEL
MINUTES
NETSERVER on (this lets other computers/servers connect to the main computer)
NISPORT 3551
Once you do all these changes, fire up the daemon and add it to your startup:
/etc/init.d/apcupsd start
rc-update add apcupsd default
Once you do this, run the command 'apcaccess' and you should get the readout from your ups. If you don't, this means you might have made a few mistakes, either you don't have a ups, it isn't plugged in, you didn't reboot after re-compiling your kernel, you don't know what you're doing, you don't know what a ups is. Anyway... let's go on, some more fun!
Take a look at this file: /etc/apcupsd/onbattery
This is a simple script that you can add anything (before the exit 0) and this script will execute all this stuff when it goes on battery (from the ONBATTERYDELAY var above). I've played around with a Nagios script that calls you on your phone with Asterisk using Cepstral Swift TTS engine. I'll detail this in another entry.
Now that you have your main Linux box connected to your ups, you want to connect another workstation or your Mac to it so it'll also shutdown. We'll use the Mac example here.
Do a Google search on 'apcupsd mac' and download the package and install it. The files will also be installed in /etc/apcupsd on your mac and you'll have to go edit the /etc/apcupsd/apcupsd.conf file.
Of course since this is a remote machine, we'll want it to shutdown sooner than the server because it only checks the server every few minutes so if the server has already decided to shutdown, then the workstation won't know what to do and it'll get powered off when the battery dies.
Let's look at /etc/apcupsd/apcupsd.conf on the mac and change these entries:
UPSCABLE ether
UPSTYPE net
DEVICE
BATTERYLEVEL 40
MINUTES 10
Once you do these, start up the apcupsd daemon, or restart it and then run 'apcaccess' and it should be reading the data from the server.
Everything should be working now! I know I've left out a lot of detail, but I've also included a lot. I figure most people reading this will be able to figure out the rest.
Have fun!
