This Docker container connects to the local APC UPS or a remote apcupsd instance. Even if running in a container it can notify the host and trigger shutdown (or other) actions, if needed. Also you can notify by Telegram of certain events and perform a healthcheck. All without special privileges.
It can also be used for any other arbitrary commands and every apcupsd trigger action.
The code is available on GitHub
With each release a new version of the image is published on DockerHub
From a container it is not possible to shutdown the host, so this needs to be done from the 'host'. To do this you must put the file 'apcupsd-trigger.sh' in '/root/apcupsd/' and add the following line to the crontab.
# /var/spool/cron/crontab/pi (generated by 'crontab -e') (on the Docker host)
* * * * * /root/apcupsd/apcupsd-trigger.sh
It is recommended to launch the image from a docker-compose as in the example.
The following are the environment variables to be defined:
Variable | Description | Value |
---|---|---|
TZ | Timezone. | Europe/Madrid |
BOT_TOKEN | Token of the bot through which we will receive Telegram notifications. | 123:ABC |
CHAT_ID | Identifier of the user or group that will receive Telegram notifications. | -123 |
HEALTH_CHECK | URL to make the health check | https://hc-ping.com/your_uuid (see healthchecks.io) |
SCHEDULE | Crontab pattern | 37 3 * * * |
The only required volume is '/tmp/apcupsd-docker' as this is the path accessed by 'apcupsd-trigger.sh' to determine whether to shutdown the host.
Other optional volumes are:
- /etc/apcupsd/doshutdown
- /etc/apcupsd/changeme
- /etc/apcupsd/commfailure
- /etc/apcupsd/commok
- /etc/apcupsd/offbattery
- /etc/apcupsd/onbattery
- /etc/apcupsd/apcupsd.conf (see below)
These volumnes can be used to override the default behavior of the image.
apcupsd needs to access the UPS and for that you need to enable UPS access.
An example and default apcupsd.conf
file is provided, but if you need to change any configuration you can modify this file and mount it as a volume.
For example, the lines below will execute doshutdown
if 5% battery is left or 10 minutes remaining, whatever happens first.
# /etc/apcupsd/apcupsd.conf (in the apcupsd-docker container)
UPSTYPE usb
DEVICE usb
BATTERYLEVEL 5
MINUTES 10
Q: I can't see any log output.
A: Allocate a tty (with docker run -t
). Apcupsd only shows output to ttys.
Q: I only see NIS server startup succeeded
A: If there is no new log line after 60 seconds, it probably is just fine. apcupsd does not log successful connections. Use apcaccess
to be sure: