├── .github └── workflows │ └── docker-image.yml ├── Dockerfile ├── README.md └── src └── docker-entrypoint /.github/workflows/docker-image.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | docker: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - id: docker_meta 11 | name: Docker Metadata action 12 | uses: docker/metadata-action@v3.3.0 13 | with: 14 | images: upshift/nut-upsd 15 | flavor: | 16 | latest=${{ github.ref == 'refs/heads/master' }} 17 | tags: | 18 | type=ref,event=branch 19 | 20 | - name: Checkout 21 | uses: actions/checkout@v2 22 | 23 | - name: Set up QEMU 24 | uses: docker/setup-qemu-action@v1 25 | 26 | - name: Set up Docker Buildx 27 | uses: docker/setup-buildx-action@v1 28 | 29 | - name: Login to DockerHub 30 | uses: docker/login-action@v1 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKERHUB_TOKEN }} 34 | 35 | - name: Build and push 36 | uses: docker/build-push-action@v2 37 | with: 38 | context: . 39 | platforms: linux/amd64,linux/arm64 40 | push: true 41 | tags: ${{ steps.docker_meta.outputs.tags }} 42 | labels: ${{ steps.docker_meta.outputs.labels }} 43 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.12 2 | 3 | LABEL maintainer="docker@upshift.fr" 4 | 5 | ENV NUT_VERSION 2.7.4 6 | 7 | ENV UPS_NAME="ups" 8 | ENV UPS_DESC="UPS" 9 | ENV UPS_DRIVER="usbhid-ups" 10 | ENV UPS_PORT="auto" 11 | 12 | ENV API_PASSWORD="" 13 | ENV ADMIN_PASSWORD="" 14 | 15 | ENV SHUTDOWN_CMD="echo 'System shutdown not configured!'" 16 | 17 | RUN set -ex; \ 18 | # run dependencies 19 | apk add --no-cache \ 20 | openssh-client \ 21 | libusb-compat \ 22 | ; \ 23 | # build dependencies 24 | apk add --no-cache --virtual .build-deps \ 25 | libusb-compat-dev \ 26 | build-base \ 27 | ; \ 28 | # download and extract 29 | cd /tmp; \ 30 | wget http://www.networkupstools.org/source/2.7/nut-$NUT_VERSION.tar.gz; \ 31 | tar xfz nut-$NUT_VERSION.tar.gz; \ 32 | cd nut-$NUT_VERSION \ 33 | ; \ 34 | # build 35 | ./configure \ 36 | --prefix=/usr \ 37 | --sysconfdir=/etc/nut \ 38 | --disable-dependency-tracking \ 39 | --enable-strip \ 40 | --disable-static \ 41 | --with-all=no \ 42 | --with-usb=yes \ 43 | --datadir=/usr/share/nut \ 44 | --with-drvpath=/usr/share/nut \ 45 | --with-statepath=/var/run/nut \ 46 | --with-user=nut \ 47 | --with-group=nut \ 48 | ; \ 49 | # install 50 | make install \ 51 | ; \ 52 | # create nut user 53 | adduser -D -h /var/run/nut nut; \ 54 | chgrp -R nut /etc/nut; \ 55 | chmod -R o-rwx /etc/nut; \ 56 | install -d -m 750 -o nut -g nut /var/run/nut \ 57 | ; \ 58 | # cleanup 59 | rm -rf /tmp/nut-$NUT_VERSION.tar.gz /tmp/nut-$NUT_VERSION; \ 60 | apk del .build-deps 61 | 62 | COPY src/docker-entrypoint /usr/local/bin/ 63 | ENTRYPOINT ["docker-entrypoint"] 64 | 65 | WORKDIR /var/run/nut 66 | 67 | EXPOSE 3493 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Network UPS Tools server 2 | 3 | Docker image for Network UPS Tools server. 4 | 5 | ## Usage 6 | 7 | This image provides a complete UPS monitoring service (USB driver only). 8 | 9 | Start the container: 10 | 11 | ```console 12 | # docker run \ 13 | --name nut-upsd \ 14 | --detach \ 15 | --publish 3493:3493 \ 16 | --device /dev/bus/usb/xxx/yyy \ 17 | --env SHUTDOWN_CMD="my-shutdown-command-from-container" \ 18 | upshift/nut-upsd 19 | ``` 20 | 21 | ## Auto configuration via environment variables 22 | 23 | This image supports customization via environment variables. 24 | 25 | ### UPS_NAME 26 | 27 | *Default value*: `ups` 28 | 29 | The name of the UPS. 30 | 31 | ### UPS_DESC 32 | 33 | *Default value*: `Eaton 5SC` 34 | 35 | This allows you to set a brief description that upsd will provide to clients that ask for a list of connected equipment. 36 | 37 | ### UPS_DRIVER 38 | 39 | *Default value*: `usbhid-ups` 40 | 41 | This specifies which program will be monitoring this UPS. 42 | 43 | ### UPS_PORT 44 | 45 | *Default vaue*: `auto` 46 | 47 | This is the serial port where the UPS is connected. 48 | 49 | ### API_USER 50 | 51 | *Default vaue*: `upsmon` 52 | 53 | This is the username used for communication between upsmon and upsd processes. 54 | 55 | ### API_PASSWORD 56 | 57 | *Default vaue*: `secret` 58 | 59 | This is the password for the upsmon user. 60 | 61 | ### SHUTDOWN_CMD 62 | 63 | *Default vaue*: `echo 'System shutdown not configured!'` 64 | 65 | This is the command upsmon will run when the system needs to be brought down. The command will be run from inside the container. 66 | 67 | -------------------------------------------------------------------------------- /src/docker-entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/sh -ex 2 | 3 | if [ -z "$API_PASSWORD" ] 4 | then 5 | API_PASSWORD=$(dd if=/dev/urandom bs=18 count=1 2>/dev/null | base64) 6 | fi 7 | 8 | if [ -z "$ADMIN_PASSWORD" ] 9 | then 10 | ADMIN_PASSWORD=$(dd if=/dev/urandom bs=18 count=1 2>/dev/null | base64) 11 | fi 12 | 13 | cat >/etc/nut/ups.conf </etc/nut/upsd.conf </etc/nut/upsd.users </etc/nut/upsmon.conf <