Network UPS Tools (NUT)

NUT Server

Pre-requisites: The Wake-on-LAN setup must be completed in order to fully use this guide

Plug your Raspberry Pi into the UPS power socket and connect them via a USB cable.

Install the Network UPS Tools server package on your Raspberry Pi.

sudo apt update
sudo apt install nut nut-server

Inspect the NUT folder.

sudo ls -l /etc/nut

You should see the following configuration files which we will be customising in this guide.

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

Identify key information about your UPS.

sudo nut-scanner

Example output:

Scanning USB bus.
No start IP, skipping SNMP
Scanning XML/HTTP bus.
No start IP, skipping NUT bus (old connect method)
Scanning IPMI bus.
[nutdev1]
	driver = "blazer_usb"
	port = "auto"
	vendorid = "0665"
	productid = "5161"
	product = "USB to Serial"
	vendor = "INNO TECH"
	bus = "003"

Back up the exiting ups.conf file as a copy and edit the main file.

Replace the file contents by matching the output from the nut-scanner output above. Use CTRL+T and then CTRL+V to clear all file contents. This defines the user and driver information of your UPS.

Example:

CTRL+O, ENTER, CTRL+X to save and exit.

Back up the exiting upsd.conf file as a copy and edit the main file.

Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents. This will enable your other devices (NUT clients) to talk to your NUT server for shutdown/power-on signals.

CTRL+O, ENTER, CTRL+X to save and exit.

Back up the exiting nut.conf file as a copy and edit the main file.

Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents. This sets your Raspberry Pi to the NUT server mode.

CTRL+O, ENTER, CTRL+X to save and exit.

Back up the exiting upsd.users file as a copy and edit the main file.

Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents. This sets the credentials for the NUT user.

CTRL+O, ENTER, CTRL+X to save and exit.

Back up the exiting upsmon.conf file as a copy and edit the main file.

Add the following as new lines to the bottom of the existing file content. This defines the actual power monitoring activities and consequent actions upon detecting a power restoration.

CTRL+O, ENTER, CTRL+X to save and exit.

Create the online.sh shell script which tells all your devices to power up when it detects that power supply to your UPS has been restored following a power outage.

Note: I am using a simple script to handle the automated power on sequence because I can't get my NUT to work as intended. Let me know if anyone managed to get yours working.

Paste the following content.

CTRL+O, ENTER, CTRL+X to save and exit.

This online.sh script makes use of the wake_devices script that we created in the Wake-on-LAN page.

Make this shell script executable but set proper permissions for security.

Restart the NUT services.

Inspect the nut-server and nut-monitor for errors.

Example output:

CTRL+C to exit logging view.

NUT Clients

The following steps need to be configured on all your other devices (e.g., validator node) to power down gracefully when there is a power outage.

Install the Network UPS Tools client on your device.

Inspect the NUT folder.

You should see the following configuration files which we will be customising in this guide.

Back up the exiting nut.conf file as a copy and edit the main file.

Replace the file contents with the following. Use CTRL+T and then CTRL+V to clear all file contents. This sets your Validator Node to the NUT server mode.

CTRL+O, ENTER, CTRL+X to save and exit.

Back up the exiting upsmon.conf file as a copy and edit the main file.

Add the following as new lines to the bottom of the existing file content. Replace IP_ADDRESS_OF_NUT_SERVER with the actual internal IP address of your Raspberry Pi. This defines the actual power monitoring activities and consequent actions upon detecting a power restoration.

CTRL+O, ENTER, CTRL+X to save and exit.

Create the onbatt.sh shell script which tells your device to shut down gracefully when it detects that power supply to your UPS has been cut off (e.g., due to a power outage).

Note: I am using a simple script to handle the automated shutdown sequence because I can't get my NUT to work as intended. Let me know if anyone managed to get yours working.

Paste the following content.

CTRL+O, ENTER, CTRL+X to save and exit.

Make this shell script executable but set proper permissions for security.

Allow the nut user to run only the /sbin/shutdown to power down your device without needing the sudo (superuser) password.

Add the following as a new line in the file.

Restart the NUT services.

Enable auto-power-on in BIOS (Optional)

This is optional as your Raspberry Pi will send a power-on signal to all your devices when power is restored but still good to have as a backup.

  1. Restart your device and press F2 repeatedly during boot to enter BIOS Setup.

  2. Select Advanced, then select the Power menu.

  3. Expand the Secondary Power Settings sub-menu and set After Power Failure to Power On.

  4. Press F10 to save and exit the BIOS Setup.

Last updated