« Bash History, setting it upHOWTO: Setup Exim to talk to postfix for local email »

HOWTO: Setup apcupsd with an APC Back-UPS RS 800

30/08/09

HOWTO: Setup apcupsd with an APC Back-UPS RS 800

Where I live, in the country :) I get one or two power fluctuations a month and a power failure two - three times a year for 5 to 30 minutes. So I decided to get a UPS so my Mail server would not go down and possibly get its file system corrupted by the sudden power failure.

The system I installed this on is running Ubuntu 8.04 64 bit. It is as most things are with Ubuntu really very easy once you read the documentation :). This howto is basically a really cut down step through the documentation for Apcupsd, which can be found here ON-Line documentation

I choose to use an APC UPS as there was freely available open source software to talk to it on Ubuntu Linux. That software being Apcupsd. I believe APC do something but that will cost a lot and probably be tricky to install and update.
Also they seem, from reviews, to be reliable and competitively priced. Replacement batteries are also easy to come by :).

After reading the docs that come with the UPS, these consisted of one large sheet with mainly pictures on it :( In fact the info they contain is common sense and has no use other than to allow APC to tick a box to say they included user documentation with their hardware.

With the battery plugged into the box and the USB cable plugged into the RJ45 connector on the UPS, If you get one you will see what I mean here. :-) Then that leaves the UPS to be plugged into the mains. The green light comes on telling you the self test was completed okay. that s pretty much the hardware setup sorted out.

Now to setup the software. :) As I said before this is basically just a case of running through the really good documentation for Apcupsd. Start at the top and work through it.

Read the section "Quick Start for beginners". I had already read through this before buying my UPS Especially part 1. Supported UPSes and Cables and part 2. Supported Operating Systems.

I intended to have only one PC, monitor and ADSL modem on the UPS so that as the documentation says "is the easy option."

Section 4. Say that using the USB connection to the UPS in the easiest and that was what I was going to do. Because I was doing the easy options I could then skip down to section 7. Building and installing. I used the Ubuntu provided packages apcupsd, apcupsd-cgi and apcupsd-docs. These are rather old compared to the current stable version of the web site for apcupsd But I was choosing the easy route.


To install the software just use the packages that are already bundled up.

sudo apt-get install apcupsd apcupsd-cgi apache2

Skipping down to Building and installing -> Installation from Binary Packages . These are created but in the right place for Ubuntu they are /etc/default/halt and /etc/init.d/halt. Take a look at the files they should have parts talking about checking for power off and usp-monitor. Mine did! :-)

sudo nano /etc/default/halt
/etc/default/halt
# Default behaviour of shutdown -h / halt. Set to "halt" or "poweroff". 
HALT=poweroff
sudo nano /etc/init.d/halt
/etc/init.d/halt
do_stop () { 
        if [ "$INIT_HALT" = "" ] 
        then 
                case "$HALT" in 
                  [Pp]*) 
                        INIT_HALT=POWEROFF 
                        ;; 
                  [Hh]*) 
                        INIT_HALT=HALT 
                        ;; 
                  *) 
                        INIT_HALT=POWEROFF 
                        ;; 
                esac 
        fi 
 
        # See if we need to cut the power. 
        if [ "$INIT_HALT" = "POWEROFF" ] && [ -x /etc/init.d/ups-monitor ] 
        then 
                /etc/init.d/ups-monitor poweroff 
        fi 


The next thing is to check the USB port in setup correctly, again mine was already. So plug the UPS into a USB port give it a second or so to find the new hardware and workout what it is etc. Skip to the USB Configuration section read through the problems/solutions part and you will get to "Verifying Device Detection and Driver"

Looking at /proc/bus/usb/devices one of the listed device should be your UPS. Mine looked like this with Jaunty but does not exist in Koala. It is not necessary and is deprecated. See here

cat /proc/bus/usb/devices
/proc/bus/usb/devices
T:  Bus=03 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  4 Spd=1.5 MxCh= 0 
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1 
P:  Vendor=051d ProdID=0002 Rev= 1.06 
S:  Manufacturer=American Power Conversion 
S:  Product=Back-UPS BR  800 FW:9.o4 .I USB FW:o4  
S:  SerialNumber=1A2345X12345   
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 24mA 
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid 
E:  Ad=81(I) Atr=03(Int.) MxPS=   6 Ivl=10ms

Now skip way on down to "After Installation" load up /etc/apcupsd/apcupsd.conf and /etc/default/apcupsd in an editor. There are a couple of things to check and possibly change in these files.

sudo gedit /etc/default/apcupsd /etc/apcupsd/apcupsd.conf

In /etc/default/apcupsd update the ISCONFIGURED line so it reads as below. This allows apcupsd to start-up.

ISCONFIGURED=yes

Now look through apcupsd.conf and update the parts you want to change. for me this was the following

UPSNAME myups
UPSCABLE usb
UPSTYPE usb
DEVICE

There are good comments all the way through this file read them and change the things you need to.


You can now restart or start apcupsd and check it is running

sudo /etc/init.d/apcupsd restart
ps fax

You can see any messages that apcupsd spits out in the /var/log files messages and apcupsd.events.

The last part to configure for me was to make sure that after a power failure the PC automatically rebooted when the power came back up again. Looking at the section Arranging for Reboot on Power-Up The was a case of rebooting and entering the BIOS. Then setting the option "PWRON after PWR-fail" to "power on".

That is all that is necessary to setup the UPS, so that your system will be protected from short power cuts of a second or two. If you have purchased a UPS that can power your system for minutes at a time it will also do that until the battery gets to around 3% or 5 minutes running time remaining. Once the UPS has been running your system for a minutes or so the software will automatically calibrate itself. You can see the status output with the following command

apcaccess status

First I configured the cgi interface so I had a nice pretty GUI to look at :-)

To get the CGI so It would run all i needed to do was allow my Apache server to run the script from apcupsd-cgi

Edit /etc/apache/apache2.conf and add the following line.

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

I then restarted my apache server

sudo /etc/init.d/apache2 restart

You should then be able to run the multimon script using a URL like this

http://YOUR_SERVER_NAME/cgi-bin/apcupsd/multimon.cgi

This link will work if you are reading this from your server. http://localhost/cgi-bin/apcupsd/multimon.cgi

You can test this by turning off the power to the UPS at the wall. After a few seconds the UPS beeps at you, any terminals you have open will get a message displayed in them and I even got a pop-up dialogue saying that I was now running on batteries. Turn the power back on and every thing returns to normal again. Since I also have email enabled I got an email from root to say the power went down and another one to say it was back up again. Cool or what!

Then after making a complete back up of my system just in case the file system got corrupt. I turned the power off at the wall again and waited the 20-30 minutes the batter can support the system. This was to check the system went down cleanly when the battery runs low and comes backup again automatically when the power is restored.

I already have my system automatically start-up all the bits and pieces I want to run on this server at power up and to close cleanly when given a halt command. Well I waited and waited. I watched the power monitor CGI slowly move. This showed the time to complete failure getting shorted and shorter. I waited and waited. The time got shorter, I waited some more. Then I got the message that the system was being shut down. Down it went nice and cleanly.


I waited a few minutes more with the system powered of and just flicked the switch for the UPS a few seconds after the UPS self test finished the PC started to boot up. Everything came back up without a hitch. The file system was
clean there were not even and journals to replay.


Pages: 1 · 2

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
What can birds and aeroplanes both do?
antispam test