Installing an APC UPS on Linux [2005-09-13]

Live example

Geekscape web server UPS status (live link) ...

Multimon: UPS Status Page
APCUPSD UPS Network Monitor
Thu Apr 24 13:24:51 EST 2014
System Model Status Battery Chg Utility UPS Load UPS Temp Batt. Run Time Data
Local Host Not available: upsfetch: tcp_open failed for 127.0.0.1 port 3551

Sadly, the "Local Host" and "Live data" links don't work when embedded in this page, use the "live link" (as above) to delve deeper

Overview

For important systems, such as business and home automation systems, it is clearly a good thing to be resilient to short duration power failures and surges. These days, Uninteruptable Power Supplies (UPS) are fairly inexpensive, at around AUS$270 for a basic unit. They are very easy to set-up and fairly well supported under Linux. So, there is every reason to get one and few excuses for not doing so. You'll rest easier during that next thunderstorm !

I chose an American Power Conversion (APC) Back-UPS CS 500, which for my current needs, one web server and ADSL modem, is likely to provide around 20 to 30 minutes of coverage with a UPS load of approximately 20%.

Some basic suggestions are ...

  • Choose a smart UPS with a USB cable (or Ethernet connection), don't get one with a serial cable
  • Get as much capacity as you can afford without breaking the bank
  • UPS batteries don't last forever, test them every 6 to 12 months, but no more than that
  • Quoting ESR ...
    • If you acquire a APC UPS, then use apcupsd
    • If you acquire anything else, then use nut
    • BatteryWholesale.com ship new batteries to international customers

There is plenty of good documentation regarding UPS and Linux ...

Description

Tested using Linux Fedora Core 4

  1. Set-up BIOS to always boot your system when power is turned on
  2. Get latest apcupsd RPM from the dries yum repository ...
    • vi /etc/yum.repos.d/dries.repos
        [dries]
        name=Extra Fedora rpms dries - $releasever - $basearch
        baseurl=http://ftp.belnet.be/packages/dries.ulyssis.org/fedora/linux/$releasever/$basearch/dries/RPMS/
        enabled=1
        gpgcheck=1
      rpm --import http://dries.studentenweb.org/ayo/RPM-GPG-KEY.dries.txt
      yum install apcupsd apcupsd-debuginfo
      
      
    • Creates the following directories ...
      • /etc/apcupsd/ (daemon configuration)
      • /etc/httpd/conf.d/apcupsd.conf (web server configuration)
      • /var/www/apcupsd (web server CGI scripts)
  3. Check that apcupsd is enabled during system boot ...
    • /sbin/chkconfig --list apcupsd
      
      
  4. Connect your APC UPS to your server using the USB cable
  5. Check that the USB device has been found ...
    •   
      cat /proc/bus/usb/devices
          P:  Vendor=051d ProdID=0002 Rev= 0.06
          S:  Manufacturer=American Power Conversion
          S:  Product=Back-UPS CS 500 FW:808.q5.I USB FW:q5
          S:  SerialNumber=BB0505003566
          I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
      
    • The udev rules should work out-of-the-box under Fedora Core 4
  6. Configure apcupsd for a simple standalone configuration using USB ...
    • vi /etc/apcupsd/apcupsd.conf
        UPSCABLE usb
        UPSTYPE usb
        DEVICE
        LOCKFILE /var/lock
        UPSCLASS standalone
        UPSMODE disable
      
  7. Configure your system halt script to power off the UPS ...
    • This patch should have occurred as part of the yum installation, but I had to do it manually
    • Insert the following towards the end of the script, after remounting the disks readonly and just before halt or reboot
    • vi /etc/rc.d/init.d/halt
        # See if this is a powerfail situation.                     # ***apcupsd***
        if [ -f /etc/apcupsd/powerfail ]; then                      # ***apcupsd***
           echo                                                     # ***apcupsd***
           echo "APCUPSD will now power off the UPS"                # ***apcupsd***
           echo                                                     # ***apcupsd***
           /etc/apcupsd/apccontrol killpower                        # ***apcupsd***
           echo                                                     # ***apcupsd***
           echo "Please ensure that the UPS has powered off before rebooting"
           echo "Otherwise, the UPS may cut the power during the reboot!!!"
           echo                                                     # ***apcupsd***
        fi
      
  8. Start the apcupsd daemon ...
    • /etc/rc.d/init.d/apcupsd start
      
      
  9. Check that the apcupsd daemon has started correctly ...
    • cat /var/log/apcupsd.events
        Sun Sep 11 03:07:57 EST 2005  apcupsd 3.10.18 (21 July 2005) redhat startup succeeded
      apcaccess status
      
      
  10. Perform various UPS tests ...
      • Process-Status Test
      • Logging Test
      • apcaccess Test
      • Communications Test
      • Simulated Power Fail Test
      • System Shutdown Test
      • Full Power Down Test
  11. Test the APC UPS hardware ...
    • The apcupsd needs to be stopped before beginning the hardware test
    • /etc/rc.d/init.d/apcupsd stop
      apctest
        2005-09-11 02:34:41 apctest 3.10.18 (21 July 2005) redhat
        Checking configuration ...
        Attached to driver: usb
        sharenet.type = DISABLE
        cable.type = USB_CABLE
      
        You are using a USB cable type, so I'm entering USB test mode
        mode.type = USB_UPS
        Setting up the port ...
        Creating the device lock file ...
        Hello, this is the apcupsd Cable Test program.
        This part of apctest is for testing USB UPSes.
        Getting UPS capabilities...SUCCESS
      
        Please select the function you want to perform.
        1) Test kill UPS power
        2) Perform self-test
        3) Read last self-test result
        4) Change battery date
        5) View battery date
        6) View manufacturing date
        7) Quit
        Select function number: 7
        2005-09-11 02:35:06 End apctest.
      /etc/rc.d/init.d/apcupsd start
      
      
    • The apcupsd needs to be restarted at the conclusion of the hardware test
  12. Provide UPS status via your web server ...
    • The yum installation should have created ...
      • /etc/httpd/conf.d/apcupsd.conf (web server configuration)
      • /var/www/apcupsd/ (web server scripts)
    • vi /etc/httpd/conf/httpd.conf
        Include /etc/httpd/conf.d/apcupsd.conf
      
  13. Test web server apcupd scripts using your web browser ...
    • firefox http://localhost/apcupsd/multimon.cgi?refresh=300  # Default is to refresh the HTML page every 30 seconds
      firefox http://localhost/apcupsd/upsfstats.cgi
      firefox http://localhost/apcupsd/upsstats.cgi
      

Copyright Notice

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License

Comments (0)