Sign inSign up

valmati/apcupsd

By valmati

•Updated over 2 years ago

apcupsd in a container; can trigger arbitrary commands on the Docker host

Image
0

9.0K

valmati/apcupsd repository overview

⁠APCUPSd

.github/workflows/docker-publish.yml

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.

⁠Source Code & Image

The code is available on GitHub⁠

With each release a new version of the image is published on DockerHub⁠

⁠Usage

⁠Host

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
⁠docker-compose

It is recommended to launch the image from a docker-compose as in the example⁠.

⁠Environment

The following are the environment variables to be defined:

VariableDescriptionValue
TZTimezone.Europe/Madrid
BOT_TOKENToken of the bot through which we will receive Telegram notifications.123:ABC
CHAT_IDIdentifier of the user or group that will receive Telegram notifications.-123
HEALTH_CHECKURL to make the health checkhttps://hc-ping.com/your_uuid⁠ (see healthchecks.io⁠)
SCHEDULECrontab⁠ pattern37 3 * * *
⁠Volumnes

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.

⁠Devices

apcupsd needs to access the UPS and for that you need to enable UPS access.

⁠Configuration Example

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

⁠FAQ

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:

Tag summary

Content type

Image

Digest

sha256:9d475a500…

Size

7.7 MB

Last updated

over 2 years ago

docker pull valmati/apcupsd