August 27, 2020

UPS for Ubuntu 20

Recently purchased two new UPS, one for Windows, another one for Ubuntu workstation. (UPS: https://en.wikipedia.org/wiki/Uninterruptible_power_supply)

Model: APC UPS, 1500VA UPS Battery Backup & Surge Protector, BX1500M

(https://www.amazon.com/gp/product/B06VY6FXMM/)

APC UPS, 1500VA UPS Battery Backup & Surge Protector, BX1500M Backup Battery, AVR, Dataline Protection and LCD Display, Back-UPS Pro Uninterruptible Power Supply

Plugged in the workstation, mid-size LCD monitor, USB hub with external power, having several devices with it, and 8 bay USB external drive.  UPS shows it can run on battery for about 60 min with everything turned on.

With recent frequent storms, power goes out briefly occasionally and this will save me from the trouble while I'm working on my computer.


S/W on Ubuntu

  • apcupsd: daemon process communicating with APC UPS
  • apcupsd-cgi: providing Web UI for APC UPS status
  • There was an old GUI application, but it no longer runs on Ubuntu 20, and not supported.

Install

$ sudo apt-get install apcupsd

If Web UI is desired, install apache:

$ sudo apt-get install apache2 apcupsd-cgi

$ apt list --installed | grep apcupsd

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

apcupsd-cgi/focal,now 3.14.14-3build1 amd64 [installed]
apcupsd-doc/focal,focal,now 3.14.14-3build1 all [installed,automatic]
apcupsd/focal,now 3.14.14-3build1 amd64 [installed]

 

I installed apcupsd-cgi although web server is not installed.  This is to analyze the CGI programs to see if I can build a front-end app without web server.  It turns out that the CGI programs are not necessary to build a GUI front-end.  I'll explain this in later section of this posting.

 

Files

Configuration files:
/etc/apcupsd/apcupsd.conf   # main
/etc/apcupsd/hosts.conf     # if other computers use this UPS
/etc/apcupsd/multimon.conf  # fields to use in CGI

Executables are in this directory,
/etc/apcupsd      
/sbin/apcaccess
/sbin/apctest


Logs,
/var/log/apcupsd.events

CGI Files,
If Apache is installed, the Web UI screen can be accessed with this URL:
http://localhost/cgi-bin/apcupsd/multimon.cgi


/usr/lib/cgi-bin/apcupsd/multimon.cgi    #
/usr/lib/cgi-bin/apcupsd/upsfstats.cgi   # works as /sbin/apcaccess
/usr/lib/cgi-bin/apcupsd/upsimage.cgi    # graph generator
/usr/lib/cgi-bin/apcupsd/upsstats.cgi    #

 

Set up

For my environment, there is only one computer using this UPS, attached via USB, and email is not configured.

$ sudo vi /etc/apcupsd/apcupsd.conf
UPSNAME APC_BX1500M
UPSCABLE usb
UPSTYPE usb
BATTERYLEVEL 5  # shutdown at battery level percentage
MINUTES 5       # remaining runtime in minutes in case of power failure to shutdown
DEVICE          # blank entry for USB

$ sudo vi /etc/default/apcupsd
ISCONFIGURED=yes

$ sudo cp /etc/apcupsd/apccontrol.orig /etc/apcupsd/apccontrol 

$ sudo systemctl restart apcupsd.service


CGI output analysis

All the CGIs come with the apcupsd-cgi package can run in console with proper environment variable set up.  The output is stored at:

https://gist.github.com/keithkim/9210a84d68730f1a71c3cffe4fd4e681

(short URL, https://bit.ly/2QyVTvD)


Upon examining the output HTMLs from the CGIs, it's nothing but providing nice looking web interface by parsing output from running apcaccess, and the log.

By issuesing man apcaccess you will see what the apcaccess output fields mean.

To build a simple GUI app just like gapcmon (see below under Reference), parsing this output is sufficient.  To provide GUI configuration screen, then it needs to provide a form and updating the configuration file, restarting the daemon process -- this will require privileged access level.

Idea - gnome shell extension would be nice, or wxPython or Tk app is good also.


Reference



2 comments:

Ed said...

I get
The requested URL was not found on this server.
Apache/2.4.41 (Ubuntu) Server at localhost Port 80

when i use the url http://localhost/cgi-bin/apcupsd/multimon.cgi

K. said...

Please check your Apache cgi-bin directory setting.