Setup apcupsd with a 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 14.04 LTS 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, you would be better off going to the link and just reading it.

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 on Linux.
Also the APC UPSes seem, from reviews, to be reliable and competitively priced. Replacement batteries are also easy to come by 🙂 .

Hardware Setup

After reading the docs that come with the UPS, which was just a single large sheet with mainly pictures on it 🙁 If you need to be told what was on it then you should not be using a computer at all!

The battery pluggs into the box and the USB cable plugs into the RJ45 connector on the UPS. That was it for hardware setup. 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.

Software Setup

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.

The hardware I am going to power via the UPS is one PC, a monitor, an ADSL modem and a Synology NAS D1813+. The documentation say this is the easy option.

Section 4. Says that using the USB connection to the UPS in the easiest and that is what I do. Sweet, two easy options in a row. 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 on the server, that is the machine directly connected to the UPS. These are rather old compared to the current stable version of the web site for apcupsd, but I was choosing the easy route. So I used the official Ubuntu packages.

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

sudo apt-get install apcupsd apcupsd-cgi apcupsd-gui

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
# Default behaviour of shutdown -h / halt. Set to "halt" or "poweroff".
HALT=poweroff
sudo nano /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”

The documentation talks about looking in, but that file does not exist on Ubuntu. To see what’s plugged into a USB port use the lsusb command. The lsusb command is also far less typing 🙂

lsusb

You should see something like list line below:

Bus 005 Device 002: ID 051d:0002 American Power Conversion Uninterrupted Power Supply

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 nano /etc/default/apcupsd

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

ISCONFIGURED=yes

Now look through apcupsd.conf and update the parts you want to change. for me this was just the following options. UPSNAME is optional.

sudo nano /etc/apcupsd/apcupsd.conf
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 service apcupsd restart

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

If you run the service status command you will see a bunch of values that are set for your APC UPS.

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 service apache2 restart

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

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

This link will work if you are reading this from your server. https://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 everything 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.

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 15-20 minutes. That’s how long the battery can support my 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 off. I waited a minute or two more and just flicked the power 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.

Setting up a client

The stand alone system was working so well and was so simple, I decided to add another PC to the mix. This PC will simply use the UPS for power and to close down after a minute in a pwoer cut.

Server side changes.

The changes to the server side config file are small. If you read the comments you should be able to work it out. I read the manual too 🙂

The next paragraph is a direct lift from the manual and has all the necessary info.

The NIS server is connected to the UPS and should be configured exactly as a standalone configuration, but with NETSERVER on. In all other respects, the server should be configured in standalone mode. You may also set the NIS server specific options NISIP to restrict which IP address of the server which apcupsd listens on. The default, 0.0.0.0, means to list on all of the server host's IP addresses; NISPORT (default 3551) to set which TCP port the server listens on; and EVENTSFILE and EVENTSFILEMAX to provide information about the last few events to clients. You may also need to modify your firewall rules on the server's host to allow traffic to the NISPORT.

Client side changes.

Install the software as before, then update the config file. Again another straight lift from the manual.

sudo apt-get install apcupsd
For the NIS client computer, you will have a configuration that looks something like what follows. What is important is that you get the information from an UPSCABLE ether with UPSTYPE net over the network and you must specify the address of a NIS server using DEVICE. The client apcupsd will then poll the NIS server specified in DEVICE every POLLTIME seconds (formerly NETTIME).
## apcupsd.conf v1.1 ##
UPSCABLE ether
UPSTYPE net
LOCKFILE /var/lock
DEVICE server-network-address:3551
UPSCLASS standalone
UPSMODE disable
POLLTIME 10
The DEVICE is set to server-address:port, where server-address is the fully qualified domain name or IP address of the apcupsd NIS server, and port is the NISPORT that the server is listening on. The default is 3551, but older versions of apcupsd used port 7000.

I also set BATTERYLEVEL and MINUTES to much tighter levels so it will shutdown quickly allowing the other server to run for longer.

Check all is well by checking to output from the comand below.

apcaccess status

All Done!

2 thoughts on “Setup apcupsd with a APC Back-UPS RS 800

  1. Manish Jain

    Hi,

    I am trying your post to set up apcupsd on my [K]Ubuntu Yakkety box installed a couple of days back. I have a BAK 700Y USB (powerchute) UPS.

    Everything seems in order. I even get decent output trying to start apcupsd :

    /etc/init.d/apcupsd restart
    [ ok ] Restarting apcupsd (via systemctl): apcupsd.service.

    But for some reason, there is no apcupsd process anywhere:

    ps -ef | grep apc
    root 4898 1766 0 22:07 pts/1 00:00:00 grep apc

    The default file has been configured, the apcupsd conf file has been configured, apctest works sweetly too : I can view/change the battery date. But apcupsd does not get up. apcaccess gets me ‘Connection refused’ (although the NIS server is on in apcupsd conf). Could you suggest what might be wrong ?

    Thanks.

    Reply
    1. Richard Post author

      run “tail -f /var/log/syslog” in a second terminal and try starting apcupsd again there should be some error output to help you out. I suspect you have a typo in the apcupsd config file.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *