If you have a UPS dedicated to your Ubuntu workstation, Ubuntu “Power Management” can meet your requirements. See details in this post.

If you have an APC UPS, another option is to use apcupsd, which is a more advanced tool to manage your APC UPS.

UPS protects the computer from (usually instantaneous, but often dangerous) surge of electricity, just connecting computer with the UPS (usually with USB connection). apcupsd is an Open Source software with excellent documentation which additionally can

  1. gracefully shut down your computer some minutes after power outage
  2. can force computer restart when the power returns (if AC back function supported by computer BIOS)

You may use command line interface or Web interface or graphical interface (gapcmon) to monitor your UPS.

The model of the APC UPS used in this tutorial is “APC Back UPS BR1500GI RS 1500VA (LI)”.

Installation

Open a terminal and type

1

sudo apt-get install apcupsd

(For information on how to install software without using command line, see this post).

After installation, directory /etc/apcupsd contains:

Concerning the executables which send email

If you want this email functionality, you have to install a message transfer agent (MTA). A lightweight option would be exim

1

sudo apt-get install exim4

Additionally, you have to forward root mail to your email, as apcupsd sends email to sysadmin by default.

See this post for details.

Concerning the UPS “killpower”

The power supply interruption in USB UPS will be done 60 sec after the shutdown of the computer. Otherwise, you have to make changes in the EEPROM of the UPS (not recommended).

Configuration

STEP 1 – Edit main configuration file

First, create a backup of main configuration file:

1

sudo cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.bak

Using your favorite text editor (nano in my case):

1

sudo nano /etc/apcupsd/apcupsd.conf

Find and edit

In most models, the following changes are enough.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

...

UPSCABLE usb

...

UPSTYPE usb

...

...

BATTERYLEVEL 30

...

MINUTES 10

STEP 2 – Edit /etc/default/apcupsd

Using your favorite text editor (nano in my case):

1

sudo nano /etc/default/apcupsd

set:

STEP 3 – Finally, restart apcupsd

Open a terminal and type:

1

sudo systemctl restart apcupsd.service

View logs

To view apcupsd logs, open a terminal and type:

1

tail /var/log/apcupsd.events

Command line interface

To get information about your UPS status, use the command:

So, in my workstation (named “athena”) the output is:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

APC      : 001,036,0875

DATE     : 2016-12-10 18:08:03 +0200

HOSTNAME : athena

VERSION  : 3.14.12 (29 March 2014) debian

UPSNAME  : athena

CABLE    : USB Cable

DRIVER   : USB UPS Driver

UPSMODE  : Stand Alone

STARTTIME: 2016-12-10 10:12:12 +0200

MODEL    : Back-UPS RS 1500G

STATUS   : ONLINE

LINEV    : 224.0 Volts

LOADPCT  : 10.0 Percent

BCHARGE  : 100.0 Percent

TIMELEFT : 66.7 Minutes

MBATTCHG : 40 Percent

MINTIMEL : 15 Minutes

MAXTIME  : 0 Seconds

SENSE    : Medium

LOTRANS  : 176.0 Volts

HITRANS  : 294.0 Volts

ALARMDEL : No alarm

BATTV    : 27.2 Volts

LASTXFER : Unacceptable line voltage changes

NUMXFERS : 0

TONBATT  : 0 Seconds

CUMONBATT: 0 Seconds

XOFFBATT : N/A

SELFTEST : NO

STATFLAG : 0x05000008

SERIALNO : 3Q1106X37131

BATTDATE : 2012-07-05

NOMINV   : 230 Volts

NOMBATTV : 24.0 Volts

NOMPOWER : 865 Watts

FIRMWARE : 878.L4 .I USB FW:L4

END APC  : 2016-12-10 18:08:05 +0200

Web interface

apcupsd offers a handy web interface to monitor your UPS. To install it, open a terminal and type

1

sudo apt-get install apcupsd-cgi

Of course, a web server is needed to use the web interface. For example, to install Apache (if not installed):

1

sudo apt-get install apache2

To access web interface, point your browser to

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

Here is the main page:

To get details, click the “Local host” link

The “All data” link is similar to apcaccess output

Graphical interface (gapcmon)

Unfortunately gapcmon is not yet available for latest Ubuntu versions (as Xenial 16.04 etc). See here for details.

However, this is how the main screen looks like:

The Historical Summary section

The Detailed information section

Test your UPS

STEP 1

Modify the TIMEOUT parameter from 0 to 60 to force the computer shutdown after 60 sec from power failure, rather than running on battery until the battery is empty.

1

sudo nano /etc/apcupsd/apcupsd.conf

Restart apcupsd service:

1

sudo systemctl restart apcupsd.service

STEP 2

Disconnect power from the UPS. Your computer should be shut down in 60 seconds.

STEP 3

Reset TIMEOUT parameter

1

sudo nano /etc/apcupsd/apcupsd.conf

Restart apcupsd service:

1

sudo systemctl restart apcupsd.service

Christos Pontikis

Entrepreneur | Full-stack developer | Founder of MediSign Ltd. I have over 15 years of professional experience designing and developing web applications. I am also very experienced in managing (web) projects.

MediSign - EHR for Small Medical Practices

EHR for Small Medical Practices

Medical records. Appointments. Electronic invoicing.

$9/month