Linux and UPS - BBox LP 500VA

I bought myself a UPS for my home server. It is a BBox LP 500VA (Model no: R-MIC-320-P201800A). I have just successfully made it work with my CentOS 5 Linux and I would like to share how I made it work as this is trivial.

The setup should do two things when working properly.
1) Supply power when power is lost.
2) Shut down the operating system gracefully after a certain period of time.

Getting no. 1 to work really needs no explanation.

As to getting the operating system - CentOS 5 Liunx in my case - to shut down gracefully has taken me quite some time. Including lots of help from Digitest, a German (English speaking) IT company that handles first line support for the product.

I first got hold of some Linux Server software off the public website. Forget that - It didn't work for me.
Then I got a different package from the support. The package is available for download from my website here: Downloads.

Here are the steps that I walk through to make the software work in my system.

You will run several "make" commands. Some of those will report errors - but that is not necessarily a problem; it wasn't on my system.

Make sure that you have a folder /usr/man/man8.

tar -xvf upseye.0.4.1.tar.gz

go to directory containing program sources:

   cd upsd-2.0b1a

clear all intermediate files:

    make clean

create dependence file:

    make depend

create upsd application:

    make

copy application to system directory:

    make install

install daemon scripts:

    make system

Now have a look in /etc/rc.d/rc5.d (if your server is running in graphical mode -rc3.d if not).
There is a file called S93ups there. That is the script that will run when your server boots.
Make sure that this script has the execute flag. I think that it doesn't by default.

Now edit this script. There is a line that reads
daemon upsd /dev/SOMETHING

make sure that you change SOMETHING to the name of your serial port.
In my instance that was
daemon upsd /dev/ttyS0

save it.

Make sure that the UPS is connected to the server using the serial cable.

Now run the script manually from a terminal:

/etc/rc.d/rc5.d/S93ups start

Have a look in your system log file. /var/log/messages now should contain something like this:
Aug 11 14:10:00 server upsd: main: v2.0b1 startup complete.
That means that the software started OK.

Now try and unplug the UPS - to make the server run on the battery.

Within 20 seconds the following should display in the log:
Aug 11 14:11:00 server upsd: log: ON BATTERY
This means that the software detected the change and is now scheduled to close down.

Now plug in the UPS again.
You should see this:
Aug 11 14:11:30 server upsd: log: OK
The software detected that we've got power again and the shutdown has been cancelled.

Finally have a look at /etc/inittab. Find the line that contains something like this:
pf::powerfail:/sbin/shutdown -f -h -+2 "Power failure; System Shutting Down"
That's the line that gets executed when the software detects that we're running on battery.
The line tells the server to schedule a shutdown in two minutes. I changed that value to +15; I expect the battery to last 15 minutes at least.


Update:
On the Microdowell website { Link } there is now a solution available that is a lot easier. You can download something called PowerPanel. Very easy to install. No compiling, runs out of the box.