nut-server on Raspberry Pi

Network UPS Tools (NUT) is an open-source software suite that lets you monitor and manage Uninterruptible Power Supplies (UPS) and other power devices across multiple systems. It provides a standardized way to interact with hundreds of different UPS models, Power Distribution Units (PDUs), and related hardware, ensuring consistent monitoring, alerting, and automated shutdowns during power events

๐Ÿš€ Docker Installation Steps

  1. Update your system
    sudo apt update && sudo apt upgrade -y
  2. Install Docker
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh 
  3. Install Docker Compose
    sudo apt install docker-compose-plugin
  4. Add your user to the Docker group
    sudo usermod -aG docker $USER
  5. Enable Docker at boot
    sudo systemctl enable docker
  6. Reboot
    sudo reboot
  7. Test Docker
    docker run hello-world

๐Ÿ“ Setup nut

This guide assumes that your pi is USB-attached to a UPS (in this specific guide I'm using an APC650). I also assume that there will be other systems using the UPS and running the nut client.

mkdir ~/docker
mkdir ~/docker/nut
mkdir ~/docker/nut/config
mkdir ~/docker/nut/logs 

๐Ÿงพ Docker Compose File

In ~/docker/nut create docker-compose.yml

  services:
  nut-server:
    image: instantlinux/nut-upsd:latest
    container_name: nut-server
    restart: unless-stopped
    privileged: true
    environment:
      - TZ=America/New_York
      - UPS_NAME=apc600        #The name you want to use for your UPS
      - UPS_DRIVER=usbhid-ups  #The driver for your UPS
      - UPS_PORT=auto          #This will detect where your UPS is plugged in
      - UPS_DESC=APC BE600M1   #This can be anything you want
      - USERNAME=YOUR-USERNAME #The username for clients to attach to the NUT server
      - PASSWORD=YOUR-PASSWORD #The password for clients to attach to the NUT server
    devices:
      - /dev/bus/usb:/dev/bus/usb
    ports:
      - "3493:3493"
    volumes:
      - ./config:/etc/nut
      - ./logs:/var/log/nut 

To determine UPS_DRIVER, go to https://networkupstools.org/stable-hcl.html and search for your UPS.

Config files

In ~/docker/nut/config you want:

nut.conf
ups.conf
upsd.conf
upsd.users
upsmon.conf

If running in a client/server mode (i.e. the UPS is attached to the pi and other devices will be triggered to shutdown by the pi), nut.conf should contain:

MODE=netserver

If running standalone (i.e. the UPS is attached to the pi and nut will only shutdown the pi), nut.conf should contain:

MODE=standalone

Add this to ups.conf:

[apc600]
  driver = usbhid-ups
  port = auto
  desc = "APC BE600M1"

Add this to upsd.conf:

LISTEN 0.0.0.0

Add this to upsd.users:

[YOUR-USERNAME]
  password = YOUR-PASSWORD
  upsmon master

Add this to upsmon.conf:

MONITOR apc600@localhost 1 YOUR_USERNAME YOUR_PASSWORD master
RUN_AS_USER nut
POWERDOWNFLAG /etc/nut/powerdown.flag
SHUTDOWNCMD "/sbin/shutdown -h +0"

โ–ถ๏ธ Start nut

From within ~/docker/nut run:

docker compose up -d

You should get an email from Watchtower pretty quickly.

๐Ÿ“œ View Logs

docker logs nut-server

If you find my content useful, please consider supporting this page:

โ˜• Buy Me a Coffee