Linux: Configure and Control APC SmartUPS During a Power Failure

Posted on in Categories , last updated November 18, 2012

My Linux nas server connected to APC SmartUPS using usb cable and I would like to detect a power failure. If power is not restored my server must shutdown when the battery is exhausted. How do I configure and use my APC SmartUPS under Debina / Ubuntu / RHEL / CentOS / Fedora / Scientific Linux operating system for power management?

Linux comes with GPL licensed open source apcupsd server ( daemon ) that can be used for power mangement and controlling most of APC’s UPS models on Linux, BSD, Unix and MS-Windows operating systems. Apcupsd works with most of APC’s Smart-UPS models as well as most simple signalling models such a Back-UPS, and BackUPS-Office. During a power failure, apcupsd will inform the users about the power failure and that a shutdown may occur. If power is not restored, a system shutdown will follow when the battery is exhausted, a timeout (seconds) expires, or runtime expires based on internal APC calculations determined by power consumption rates.

Step #1: Install Apcupsd

Type the following apt-get command under Debian / Ubuntu Linux install apcupsd software:
# apt-get install apcupsd
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  apcupsd-cgi hal
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/291 kB of archives.
After this operation, 672 kB of additional disk space will be used.
Selecting previously deselected package apcupsd.
(Reading database ... 30840 files and directories currently installed.)
Unpacking apcupsd (from .../apcupsd_3.14.8-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up apcupsd (3.14.8-2) ...
update-rc.d: warning: apcupsd start runlevel arguments (1 2 3 4 5) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: apcupsd stop runlevel arguments (0 6) do not match LSB Default-Stop values (0 1 6)
Please check your configuration ISCONFIGURED in /etc/default/apcupsd

Edit /etc/default/apcupsd, enter:
# vi /etc/default/apcupsd
Save and close the file. If you are using RHEL / CentOS Linux use yum command as follows, enter:
# yum install apcupsd
Sample outputs:

Loaded plugins: product-id, protectbase, rhnplugin, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
0 packages excluded due to repository protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package apcupsd.x86_64 0:3.14.10-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
 Package               Arch                 Version                        Repository          Size
 apcupsd               x86_64               3.14.10-1.el6                  epel               299 k
Transaction Summary
Install       1 Package(s)
Total download size: 299 k
Installed size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
apcupsd-3.14.10-1.el6.x86_64.rpm                                             | 299 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apcupsd-3.14.10-1.el6.x86_64                                                     1/1 
Installed products updated.
  Verifying  : apcupsd-3.14.10-1.el6.x86_64                                                     1/1 
  apcupsd.x86_64 0:3.14.10-1.el6                                                                    

Step 2: Connect UPS

You need to connect the UPS to your server using cable. You will see the following entry in /var/log/messages

Jul 28 14:11:18 nas02 kernel: [    3.060349] usb 2-1: Product: Back-UPS RS 1500 FW:8.g9a.I USB FW:g9a
Jul 28 14:11:18 nas02 kernel: [    5.348979] generic-usb 0003:051D:0002.0001: hiddev0,hidraw0: USB HID v1.10 Device [American Power Conversion Back-UPS RS 1500 FW:8.g9a.I USB FW:g9a] on usb-0000:00:10.0-1/input0

Step #3: Configure UPS

Edit /etc/apcupsd/apcupsd.conf, enter:
# vi /etc/apcupsd/apcupsd.conf
First, give your UPS a name. This is particulary useful if you have multiple UPSes. This does not set the EEPROM. It should be 8 characters or less:

UPSNAME homeups1

Next, defines the type of cable connecting the UPS to your Linux server. In this example, I’m connecting my UPS using usb:


Possible generic choices for cable are – simple, smart, ether, and usb. Or a specific cable model number may be used such as 940-0119A. For USB UPSes, please leave the DEVICE directive blank. For
other UPS types, you must specify an appropriate port or address (see config file):

## set ups type to usb ##

Configuration parameters used during power failures

The ONBATTERYDELAY directive defined the time in seconds from when a power failure s detected until we react to it with an onbattery event:


If during a power failure, the remaining battery percentage (as reported by the UPS) is below or equal to BATTERYLEVEL, apcupsd will initiate a Linux system shutdown:


If during a power failure, the remaining runtime in minutes (as calculated internally by the UPS) is below or equal to MINUTES, apcupsd, will initiate a system shutdown.


If during a power failure, the UPS has run on batteries for TIMEOUT many seconds or longer, apcupsd will initiate a system shutdown. A value of 0 disables this timer:


Note: If you have an older dumb UPS, you will want to set this to less than the time you know you can run on batteries.

Configuration apcupsd network information server

You can use CGI or GUI programs from remote system to get information about your UPS. Turn on network information server:


Set IP address on which NIS server will listen for incoming connections. You need to configure this setting to any specific IP address of your server and NIS will listen for connections only on that interface. Use the loopback address ( to accept connections only from the local machine (default).

### example - for lan users ###

The default port is set to 3551for sending STATUS and EVENTS data over the network:


Save and close the file.

Step #4: Test ups

Type the following command:
# apctest
Sample outputs:

2012-07-29 16:52:40 apctest 3.14.8 (16 January 2010) debian
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 ...
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)  View/Change battery date
5)  View manufacturing date
6)  View/Change alarm behavior
7)  View/Change sensitivity
8)  View/Change low transfer voltage
9)  View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
 Q) Quit
Select function number:

You can test your ups or read test results.

How do I start apcupsd server?

Type the following command to start / stop / restart service:
# /etc/init.d/apcupsd start
# /etc/init.d/apcupsd stop
# /etc/init.d/apcupsd restart

RHEL / CentOS / Red Hat / Fedora Linux can use the same command. However, you need to turn on service on boot:
# chkconfig apcupsd on

How do I see current status of my UPS?

Type the following command:
# apcaccess
Sample outputs:

APC      : 001,037,0952
DATE     : 2012-07-29 16:58:36 +0530  
VERSION  : 3.14.8 (16 January 2010) debian
CABLE    : USB Cable
MODEL    : Back-UPS RS 1500 
UPSMODE  : Stand Alone
STARTTIME: 2012-07-29 16:58:34 +0530  
LINEV    : 226.0 Volts
LOADPCT  :  11.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT : 283.5 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 194.0 Volts
HITRANS  : 264.0 Volts
BATTV    : 26.9 Volts
LASTXFER : Automatic or explicit self test
TONBATT  : 0 seconds
CUMONBATT: 0 seconds
STATFLAG : 0x07000008 Status Flag
MANDATE  : 2007-07-26
BATTDATE : 2007-07-26
NOMINV   : 230 Volts
NOMBATTV :  24.0 Volts
NOMPOWER : 865 Watts
FIRMWARE : 8.g9a.I USB FW:g9a
APCMODEL : Back-UPS RS 1500 
END APC  : 2012-07-29 16:58:39 +0530  

How do I view ups events such as power failure?

The UPS status is logged in /var/log/ file. To view this file, enter:
# tail -f /var/log/
Sample outputs:

2012-07-29 03:36:21 +0530  apcupsd 3.14.8 (16 January 2010) debian startup succeeded
2012-07-29 03:38:06 +0530  apcupsd exiting, signal 15
2012-07-29 03:38:06 +0530  apcupsd shutdown succeeded
2012-07-29 03:49:54 +0530  apcupsd 3.14.8 (16 January 2010) debian startup succeeded
2012-07-29 07:08:52 +0530  Power failure.
2012-07-29 07:08:54 +0530  Power is back. UPS running on mains.
2012-07-29 11:24:32 +0530  Power failure.
2012-07-29 11:24:35 +0530  Power is back. UPS running on mains.
2012-07-29 14:34:43 +0530  Power failure.
2012-07-29 14:34:47 +0530  Power is back. UPS running on mains.

A note about desktop GUI monitoring tool

Gapcmon is a desktop monitor program for the apcupsd server. You can install it using the following command:
# apt-get install gapcmon
OR use yum command for RHEL / CentOS Linux:
# yum install apcupsd-gui
Run it as follows:
$ gapcmon

A note about web based monitoring tool

You can install a package called apcupsd-cgi so that you can monitor your UPS load, uptime, logs and other details using www. Type the following apt-get command to install the same:
# apt-get install apcupsd-cgi
OR use yum command for RHEL / CentOS Linux:
# yum install apcupsd-cgi
You need to configure Apache web server with cgi-bin or lighttpd server with cgi-bin server. Once configured, type the url as follows using any web-browser:
Sample outputs from both desktop and web-base gui monitor tools:

Check out related media

This tutorial also available in video format:

(Video.01: Installing apc usp under Debian / Ubuntu Linux. Can’t view video? Click here.)

  • APCUPSD project.
  • man page – apcupsd, apt-get, and yum command.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

17 comment

  1. Is there a way to do the server config easily? I’m not understanding that part of this. But the panel has a XFCE-power-manager 1.0.11 on the panel. apcaccess returns nada in the termnal.

    [email protected]:~$ apctest
    2012-07-31 18:27:10 apctest 3.14.10 (13 September 2011) debian
    Checking configuration ...
    Terminating due to configuration file errors.
    apctest error termination completed
    [email protected]:~$ apcaccess
    Error contacting apcupsd @ localhost:3551: Connection refused
    [email protected]:~$ tail -f /var/log/
    tail: cannot open `/var/log/' for reading: No such file or directory
    [email protected]:~$ /etc/init.d/apcupsd start
    Starting UPS power management: Terminating due to configuration file errors.
    [email protected]:~$ /etc/init.d/apcupsd stop
    Stopping UPS power management: No process in pidfile '/var/run/' found running; none killed.
    [email protected]:~$ /etc/init.d/apcupsd restart
    Stopping UPS power management: No process in pidfile '/var/run/' found running; none killed.
    Starting UPS power management: Terminating due to configuration file errors.
    [email protected]:~$ /var/log/messages
    bash: /var/log/messages: No such file or directory
    [email protected]:~$
  2. On newer versions of Fedora (16+?), systemctl is preferred over /etc/init.d scripts and chkconfig. Here are the commands that worked for me:

    # cat /etc/fedora-release
    Fedora release 19 (Schrödinger’s Cat)
    # yum list apcupsd
    Loaded plugins: langpacks, refresh-packagekit
    Installed Packages 
    apcupsd.x86_64                                                  3.14.10-10.fc19                                                  @fedora 


    # systemctl enable apcupsd.service
    ln -s '/usr/lib/systemd/system/apcupsd.service' '/etc/systemd/system/'
    # systemctl start apcupsd.service
    # systemctl status apcupsd.service
    apcupsd.service - APC UPS Power Control Daemon for Linux
       Loaded: loaded (/usr/lib/systemd/system/apcupsd.service; enabled)
       Active: active (running) since Sat 2013-12-07 12:54:41 EST; 30s ago
      Process: 2047 ExecStartPre=/bin/rm -f /etc/apcupsd/powerfail (code=exited, status=0/SUCCESS)
     Main PID: 2049 (apcupsd)
       CGroup: name=systemd:/system/apcupsd.service
               └─2049 /sbin/apcupsd -b -f /etc/apcupsd/apcupsd.conf
    Dec 07 12:54:41 pinot-noir systemd[1]: Starting APC UPS Power Control Daemon for Linux...
    Dec 07 12:54:41 pinot-noir systemd[1]: Started APC UPS Power Control Daemon for Linux.
    Dec 07 12:54:42 pinot-noir apcupsd[2049]: apcupsd 3.14.10 (13 September 2011) redhat startup succeeded
    Dec 07 12:54:42 pinot-noir apcupsd[2049]: NIS server startup succeeded
  3. Great post! Many thanks. Set up a new APC BX1500G on my home network. The APC chat support said it supports only Windows monitor apps. But I wanted to use a nearby raspberry pi for the job. Your post worked perfectly under the raspian OS. The pi will inform other servers when to shut down. Thanks again. It saved me a ton of time.

  4. Hi, I’ve implemented well on Debian. And I have configured BIOS motherboard to power up PC when energy return. It sends email on power out, power back, and shutdown events. But how could I make it to send email when the power come back after a shutdown was made by exhaust?
    Something regards apcupsd? o just when Debian boot up?
    What would be the best choice? Any advice?

    Thanks in advance!

Leave a Comment