Portainer Templates logo

Portainer Templates

NUT Server NUT Server

Container

OtherTools

The purpose of NUT Server is to monitor a UPS attached device

Image details

Pulls: 2.1M
Architecture: amd64, arm64, arm/v7, arm/v6
Image size: 17 MB
Latest: 2.8.3-r4
User: instantlinux
Created: Sep 18, 2017
Updated: 7 days ago
Status: active

Configuration

Type
Container
Platform
linux
Image
instantlinux/nut-upsd:latest
Ports
3493:3493/tcp
Env vars
PUID=1000PGID=1000SERIAL=noneNAME=noneVENDOR ID=noneAPI_PASSWORD=noneDESCRIPTION=none
Restart
unless-stopped

Template by novaspirit

Notes

Template created by Pi-Hosted Series
Check our Github page: https://github.com/pi-hosted/pi-hosted

Official Webpage: https://networkupstools.org
Official Docker Documentation: https://hub.docker.com/r/instantlinux/nut-upsd


Standalone Install

Select an install method, to see config/commands for deploying NUT Server

Installation method

Install on Portainer

Import all app templates into your Portainer instance, for easy 1-click deploys

  1. Ensure both Docker and Portainer are installed, and up-to-date
  2. Log into your Portainer web UI
  3. Under Settings → App Templates, paste the below URL
  4. Head to Home → App Templates, and the list of apps will show up
  5. Select NUT Server, fill in any config options, and hit Deploy

Template Import URL

https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json
Show Me demo

More install options in our documentation.

nut-upsd


The Network UPS Tools (nut) package in an Alpine container, with enough configuration to support Nagios monitoring of your UPS units. This multi-architecture image supports Intel/AMD and ARM (Raspberry Pi etc).

Usage

See the kubernetes.yaml / docker-compose.yml files provided here in the source directory; this needs to run in privileged mode in order to access USB devices.
Pick a random password for the API user and place it in a Docker secret (if you're not using swarm or kubernetes, put it in the filepath as shown at bottom of docker-compose.yml, e.g. /var/adm/admin/secrets/nut-upsd-password).
This will expose TCP port 3493; to reach it with the standard Nagios plugin, set up a service to invoke:
/usr/lib/nagios/plugins/check_ups -H <dockerhost> -u <name> [ -p <port> ]

As a read-only service intended for monitoring, this container makes no attempt to lock down network security.
Verified with the most-common type of UPS, the APC consumer-grade product; Tripp Lite models also (probably) work. CyberPower models need a MAXAGE parameter set longer than default (25). Note that the usbhid-ups driver for APC requires you to provide the correct 12-digit hardware serial number. All other parameter defaults will work.
If you have a different model of UPS, contents of the files ups.conf, upsd.conf, upsmon.conf, and/or upsd.users can be overridden by mounting them to /etc/nut/local.
If you have more than one UPS connected to a host, run more than one copy of this container and bind the container port 3493 from each to a separate TCP port.
This repo has complete instructions for building a kubernetes cluster where you can launch with helm or kubernetes.yaml using make and customizing Makefile.vars after cloning this repo: ~ git clone https://github.com/instantlinux/docker-tools.git cd docker-tools/k8s

This make target is defined in Makefile.instances

make nut-01
~

Variables

These variables can be passed to the image from kubernetes.yaml or docker-compose.yml as needed:
Variable | Default | Description | -------- | ------- | ----------- | ACTIONS | | One or more user actions allowed (set, fsd) APIUSER | upsmon| API user APIPASSWORD | | API password, if not using secret DESCRIPTION | UPS | user-assigned description DRIVER | usbhid-ups | driver (see compatibility list) GROUP | nut | local group INSTCMDS | | all or list of allowed commands, see cmdvartab CMDDESC values MAXAGE | 15 | seconds before declaring driver non-responsive NAME | ups | user-assigned config name NOTIFYCMD | | full path of script to run upon notification NUTDEBUGLEVEL | 0 | verbosity of debug messages NUTQUIETINITSSL | true | inhibit superfluous startup warning NUTQUIETINITUPSNOTIFY | true | inhibit superfluous startup warning POLLINTERVAL | | Poll Interval for ups.conf PORT | auto | device port (e.g. /dev/ttyUSB0) on host SDORDER | | UPS shutdown sequence, set to -1 to disable shutdown SECRETNAME | nut-upsd-password | name of secret to use for API user SERIAL | | hardware serial number of UPS SERVER | primary | primary instance shuts down after secondaries ULIMIT | 2048 | open-files ulimit USER | nut | local user VENDORID | | vendor ID for ups.conf

Notes

To define a notify script, volume-mount it via your docker-compose file under /usr/local/bin or in your helm values overrides and set the NOTIFYCMD environment variable. (Don't mount any executable scripts under /etc/nut, put them under /usr/local).
If you need a driver other than usbhid-ups, the full list of supported drivers can be listed as follows:
docker run --rm --entrypoint /bin/ls instantlinux/nut-upsd /usr/lib/nut
The entrypoint script can set parameters based on the above environment variables; each driver has its own parameters (which can be configured by mounting your own ups.conf file) as documented:
MYDRIVER=liebert
docker run --rm --entrypoint /usr/lib/nut/$MYDRIVER instantlinux/nut-upsd -h
Network UPS Tools - Liebert MultiLink UPS driver 1.02 (3.15.0_alpha20210804-3402-gced1683082)
Warning: This is an experimental driver.
Some features may not function correctly.


usage: liebert -a <id> [OPTIONS]
  -a <id>        - autoconfig using ups.conf section <id>
                 - note: -x after -a overrides ups.conf settings

  -V             - print version, then exit
  -L             - print parseable list of driver variables
  -D             - raise debugging level
  -q             - raise log level threshold
  -h             - display this help
  -k             - force shutdown
  -i <int>       - poll interval
  -r <dir>       - chroot to <dir>
  -u <user>      - switch to <user> (if started as root)
  -x <var>=<val> - set driver variable <var> to <val>
                 - example: -x cable=940-0095B

Acceptable values for -x or ups.conf in this driver:

              Override manufacturer name : -x mfr=<value>
                     Override model name : -x model=<value>

For Tripp Lite models, you may need to specify VENDORID 09ae in the environment. Also check to see if you need a POLLINTERVAL setting. For any make or model, here's how to identify the idVendor and iSerial values from a root shell on your host:
# lsusb
 ...
Bus 001 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
# lsusb -D /dev/bus/usb/001/005
Device: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
 ...
  idVendor           0x051d American Power Conversion
  idProduct          0x0002 Uninterruptible Power Supply
  bcdDevice            0.90
  iManufacturer           1 American Power Conversion
  iProduct                2 Back-UPS RS 1500G FW:865.L6 .D USB FW:L6
  iSerial                 3 4B1624P26350

If you require udev rules to set permissions, configure your host prior to running the container. For example:
cat >/etc/udev/rules.d/99-usb-serial.rules <<EOF
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}==“09ae”, ATTRS{idProduct}==“2012”, MODE="0660", GROUP="nut"
EOF
udevadm control --reload-rules && udevadm trigger

When starting up under Debian trixie, an out-of-memory error can be prevented by setting the nofile ulimit to a smaller value than system default: see issue #1672. The default is set here to 2048.
If you see this error message on startup:
Unable to use old-style MONITOR line without a username
Convert it and add a username to upsd.users - see the documentation
the most likely cause is a missing or empty secret (nut-upsd-password).

Secrets

If the API user needs a password, you have two ways to specify it: pass the value itself as environment variable APIPASSWORD (which isn't secure), or define a Docker secret as follows:
SecretDescription
nut-upsd-passwordPassword for API user

Contributing

If you want to make improvements to this image, see CONTRIBUTING
.

Serve NUT Server on your own domain behind Caddy, Nginx or Traefik. Fill in your domain and copy the result. It's a starting point, some apps need their own base URL or extra headers set too.

Proxying nut-server.example.com to http://NUT Server:3493

Add this to your Caddyfile

nut-server.example.com {
	reverse_proxy http://NUT Server:3493
}

Check the logs first

Nine times out of ten the logs tell you exactly what went wrong.

  • In Portainer, go to Containers, click the container, then Logs. Or run docker logs NUT Server
  • Exit codes help too: 137 means killed, usually out of memory. 126 or 127 means the command inside the image is broken.

Port already in use

If deployment fails with "Bind for 0.0.0.0:3493 failed: port is already allocated", something else on your server is using that port.

  • Find what's using it: sudo ss -tlnp | grep :3493
  • Stop the other service, or pick a different host port. In 3493:3493 only the left number is yours to change, the right one belongs to the app.

Running but the page won't load

The container is up but nothing appears in your browser.

  • Use your server's real IP: http://your-server-ip:3493. The 0.0.0.0 link Portainer shows isn't a real address.
  • Give it a minute after first deploy, NUT Server can take a while to initialise.
  • Make sure your firewall allows the port, e.g. sudo ufw allow 3493

Image won't pull

Test the pull directly on the host: docker pull instantlinux/nut-upsd:latest

  • "manifest unknown" means the tag no longer exists. This template uses latest, so try pinning a specific version instead.
  • "toomanyrequests" is the Docker Hub rate limit. Log in with docker login to raise it.
  • "no space left on device" means a full disk. Reclaim space with docker system prune

"exec format error"

This means the image was built for a different CPU architecture than your server.

  • This image supports: amd64, arm64, arm/v7, arm/v6
  • Check yours with uname -m: x86_64 is amd64, aarch64 is arm64. Raspberry Pi and other ARM boards are the usual culprits.

Container keeps restarting

The unless-stopped restart policy relaunches the app after every crash, so the real error can scroll past.

  • Check the logs right after a restart, the last few lines before it died are the useful ones.
  • Get the exit code with docker inspect NUT Server --format '{{.State.ExitCode}}'
  • Still stuck? Redeploy once with the restart policy set to no so the failure stays visible.

Data disappears when the container is recreated

This template doesn't define any volumes, so everything NUT Server saves lives inside the container and is lost on update or recreate.

  • Add a volume mapping for NUT Server's data folder before storing anything you care about.

Raise an issue

Found something which isn't working as it should? Here's how to report it.

A single container

NUT Server runs as one container, the simplest kind of app here. Just the one image to pull and nothing else wired up alongside it.

The app image

An image is the app packed up ready to go, everything NUT Server needs bundled into one download. This template pulls instantlinux/nut-upsd:latest, which Docker fetches once (about 17 MB) and then starts your own copy from.

Where the image comes from

Docker pulls its images from registries, public libraries of ready-built apps. NUT Server's comes from Docker Hub, published by instantlinux.

Version tags

The bit after the colon in the image name is the version tag. Here it's latest, which always points at the newest build, so a redeploy can bump you to a newer release without you asking. Newest right now is 2.8.3-r4. Pin a specific tag if you would rather stay on one version.

Which machines it runs on

Every image is built for particular CPU types. This one ships for amd64, arm64, arm/v7, arm/v6, so it runs on both regular x86 servers and ARM boards like a Raspberry Pi.

Ports

A port is the door the app answers on. A mapping like 3493:3493 means it's reachable on port 3493 of your server, where the left number is yours to change and the right one belongs to the app. It opens:

  • 3493:3493

No stored data

This template doesn't mount any storage, so whatever NUT Server writes stays inside the container and is wiped if it's recreated or updated. That's fine for something stateless, but add a volume before trusting it with anything you want to keep.

Environment variables

Environment variables are the settings you hand over when you deploy, things like a password or a timezone. NUT Server takes 7 of them, all with defaults you can leave alone or tweak:

  • PUID, defaults to 1000
  • PGID, defaults to 1000
  • SERIAL, defaults to none
  • NAME, defaults to none
  • VENDOR ID, defaults to none
  • API_PASSWORD, defaults to none
  • DESCRIPTION, defaults to none

Restart policy

The restart policy here is unless-stopped, so Docker restarts NUT Server after a crash or reboot, but leaves it off when you stop it on purpose. You can change this on the deploy screen. The choices are no (never restart), on-failure (only after a crash), unless-stopped (restart unless you stop it), and always (bring it back no matter what).

Users and permissions

The PUID and PGID settings tell it which user and group to act as on your host. Point them at your own account (find yours with id $USER) so the files it writes into your mounted folders come out owned by you rather than root.

Networking

Nothing custom is set, so NUT Server sits on Docker's default bridge network: its own private space that reaches the outside world only through the ports it publishes.

Container name

Once it's deployed, Portainer names the container NUT Server. That's what you'll spot in the containers list and use in commands like docker logs NUT Server.

Platform

The platform is linux, the kind of system the container is built to run on. Docker and Portainer handle this on a normal Linux server.

Portainer app templates

Zooming out, this whole page comes from a Portainer app template: a short recipe telling Portainer how to set NUT Server up. Add the template list to Portainer once, then deploying NUT Server is a click rather than a wall of config.