Replace the file contents with the following. This will enable your other devices (NUT clients) to talk to your NUT server for shutdown/power-on signals. Use CTRL+T and then CTRL+V to clear all file contents.
LISTEN 0.0.0.0 3493
CTRL+O, ENTER, CTRL+X to save and exit.
Back up the exiting nut.conf file as a copy and edit the main file.
Add the following as new lines to the bottom of the existing file content.
MONITORnutdev1@localhost1upsmonsecretmaster#"upsmon", "secret", and "master" need to match the contents of the upsd.users set aboveNOTIFYFLAGONLINESYSLOG+EXEC+WALLNOTIFYCMD/etc/nut/online.sh# we will create this shell script later
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.
sudonano/etc/nut/online.sh
Paste the following content.
#!/bin/bash# Log the start of the scriptlogger"NUT: Checking UPS status for ONLINE event"# Fetch the UPS statusstatus=$(upscprolink@localhostups.status)# Check if the UPS is on batteryif [[ "$status"=="OL" ]]; thenlogger"NUT: UPS on line power detected. Waiting 60 seconds before powering up all devices."# Wait for 60 secondssleep60# Log the shutdown initiationlogger"NUT: Initiating power up after 60-second delay."/usr/local/bin/wake_devices"UPS online"elselogger"NUT: UPS status is not ONLINE (status: $status). No power up triggered."fi
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.
Inspect the nut-server and nut-monitor for errors.
sudo journalctl -fu nut-server -o cat | ccze -A
sudo journalctl -fu nut-monitor -o cat | ccze -A
Example output:
#nut-serverStartingNetworkUPSTools-powerdevicesinformationserver...fopen/run/nut/upsd.pid:Nosuchfileordirectorylisteningon0.0.0.0port3493listeningon0.0.0.0port3493ConnectedtoUPS [prolink]: blazer_usb-prolink ConnectedtoUPS [prolink]: blazer_usb-prolink StartupsuccessfulStartedNetworkUPSTools-powerdevicesinformationserver.Usermonuser@127.0.0.1loggedintoUPS [prolink]#nut-monitorStartingNetworkUPSTools-powerdevicemonitorandshutdowncontroller...fopen/run/nut/upsmon.pid:NosuchfileordirectoryUPS:prolink@localhost (master) (powervalue1) Usingpowerdownflagfile/etc/killpowerStartupsuccessfulnut-monitor.service:Can't open PID file /run/nut/upsmon.pid (yet?) after start: Operation not permitted nut-monitor.service: Supervising process 1206 which is not our child. We'llmostlikelynotnoticewhenitexits.StartedNetworkUPSTools-powerdevicemonitorandshutdowncontroller.nut-monitor.service:Supervisingprocess1206whichisnotourchild.We'll most likely not notice when it exits. nut-monitor.service: Supervising process 1206 which is not our child. We'llmostlikelynotnoticewhenitexits.
CTRL+C to exit logging view.
NUT Clients (WIP)
The following steps need to be configured on all your other devices to power down gracefully when there is a power outage.
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.
sudonano/etc/nut/onbatt.sh
Paste the following content.
#!/bin/bash# Log the start of the scriptlogger"NUT: Checking UPS status for ONBATT event"# Fetch the UPS statusstatus=$(upscprolink@localhostups.status)# Check if the UPS is on batteryif [[ "$status"=="OB" ]]; thenlogger"NUT: UPS on battery power detected. Waiting 60 seconds before shutting down."# Wait for 60 secondssleep60# Log the shutdown initiationlogger"NUT: Initiating shutdown after 60-second delay."sudo/sbin/shutdown-hnow"UPS on battery power"elselogger"NUT: UPS status is not ONBATT (status: $status). No shutdown triggered."fi
CTRL+O, ENTER, CTRL+X to save and exit.
Make this shell script executable.
sudochmod+x/etc/nut/onbatt.sh
Allow the nut user to run only the /sbin/shutdown to power down your device without needing the sudo (superuser) password.