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
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.
$ sudo apt-get install apcupsd
$ 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.
- apcupsd user manual, http://apcupsd.org/manual/manual.html
- man page, https://help.ubuntu.com/community/apcupsd
/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,
If Apache is installed, the Web UI screen can be accessed with this URL:
/usr/lib/cgi-bin/apcupsd/upsfstats.cgi # works as /sbin/apcaccess
/usr/lib/cgi-bin/apcupsd/upsimage.cgi # graph generator
For my environment, there is only one computer is using this UPS, attached via USB, and email is not configured.
$ sudo vi /etc/apcupsd/apcupsd.conf
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
$ 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:
(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.
- apcupsd source code, https://sourceforge.net/projects/apcupsd/
- gapcmon - old GUI app, no longer works, http://gapcmon.sourceforge.net