What is this?
Guide to install apcupsd on Raspberry Pi OS (Raspbian) and get its web interfact running with Apache
What is apcupsd?
apcupsd is an open source UPS mangement and control software target at APC UPSes.
First, install apcupsd utility, and the dynamic web page monitor.
sudo apt-get -y install apcupsd
Upon install, it should place you into an editor for /etc/apcupsd/apcupsd.conf
If you are using APC Back-UPS RS 1000MS and are connected to the Raspberry Pi via USB cable, the configuration file will be like this:
## apcupsd.conf v1.1 ##
UPSNAME {insert your name here}
# UPSCABLE <cable>
UPSCABLE usb
# UPSTYPE
UPSTYPE usb
DEVICE
# NISIP <dotted notation ip address>
NISIP 0.0.0.0
I left all other settings at their default.
After saving the configuration file, restart the apcupsd service.
sudo systemctl restart apcupsd
If everything has gone right, you should see active (running)
when running:
sudo systemctl status apcupsd
To see the current status of the UPS, run:
sudo apcaccess
To monitor the UPS online (via LAN network),
Install Apache 2.4.
sudo apt-get -y install apache2
Then, backup the default configuration files.
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.orig
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.orig
Now, we must edit the apache configuration file.
cd /etc/apache2/
sudo nano apache2.conf
Find the following section:
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
After this block, append the following:
# apcupsd
ScriptAlias /apcupsd/ /usr/lib/cgi-bin/apcupsd/
<Directory "/usr/lib/cgi-bin/apcupsd">
DirectoryIndex upsstats.cgi
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex upsstats.cgi
Require all granted
</Directory>
Finally, at the bottom of apache2.conf
, append:
ServerName localhost
Save and exit.
Next, we need to edit the website configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Find the following chunk:
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
# Include conf-available/serve-cgi-bin.conf
Uncomment Include conf-available/serve-cgi-bin.conf
and underneath, append:
# apcupsd-cgi
ScriptAlias /apcupsd/ /usr/lib/cgi-bin/apcupsd/
<Directory "/usr/lib/cgi-bin/apcupsd">
DirectoryIndex multimon.cgi
Options +FollowSymLinks +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex upsstats.cgi
Require all granted
</Directory>
Save and exit.
Enable the CGI module
sudo a2enmod cgi
After saving the configuration files, run configtest
to check syntax errors. If everything goes right, you will see Syntax OK
:
sudo apache2ctl configtest
Finally, install the apcupsd-cgi package:
sudo apt-get -y install apcupsd-cgi
The only thing left is to go to the web address: http://localhost/apcupsd/
If you have the IP address of your pi, substitute it for localhost
in the above url.
If you want apcupsd to email you or send a message via a messaging app upon power loss/restoration, see this example implementation.