Can't get NUT to shutdown Proxmox

Zolt

Member
Nov 21, 2021
13
4
8
44
Hi all,

I have an APC UPS that is configured via NUT on Pfsense. I have two other servers (TrueNAS and a Windows box) connected as NUT clients and they successfully shutdown with a loss of power.

I have Proxmox successfully seeing the UPS (checking via "upsc"), but no matter what I put in the config files, it won't shutdown on a loss of power.

If I turn off the power as a test, I see the following on the Proxmox server:

Nov 21 17:50:32 pve upsmon[850]: Communications with UPS APC@192.168.0.2:3493 established Nov 21 17:53:17 pve upsmon[850]: UPS APC@192.168.0.2:3493 on battery Nov 21 17:54:42 pve upsmon[850]: UPS APC@192.168.0.2:3493 on line power

So the server can see that the UPS goes on battery, and I've attempted to set the shutdown timer to 20 seconds. But the server doesn't shutdown. Maybe I've got something wrong in the config files?

upsmon.conf
MONITOR APC@192.168.0.2:3493 1 monslave XXX SLAVE RUN_AS_USER root NOTIFYCMD "/usr/local/sbin/upssched" NOTIFYFLAG ONBATT SYSLOG+EXEC NOTIFYFLAG LOWBATT SYSLOG+EXEC NOTIFYFLAG ONLINE SYSLOG+EXEC NOTIFYFLAG COMMBAD SYSLOG+EXEC NOTIFYFLAG COMMOK SYSLOG+EXEC NOTIFYFLAG REPLBATT SYSLOG+EXEC NOTIFYFLAG NOCOMM SYSLOG+EXEC NOTIFYFLAG FSD SYSLOG+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+EXEC SHUTDOWNCMD "/sbin/shutdown -h now" POWERDOWNFLAG /etc/nokillpower HOSTSYNC 15

upssched.conf
CMDSCRIPT /bin/upssched-cmd PIPEFN /var/run/nut/upssched/upssched.pipe LOCKFN /var/run/nut/upssched/upssched.lock AT NOCOMM * EXECUTE NOTIFY-NOCOMM AT COMMBAD * START-TIMER NOTIFY-COMMBAD 10 AT COMMOK * CANCEL-TIMER NOTIFY-COMMBAD COMMOK AT FSD * EXECUTE NOTIFY-FSD AT LOWBATT * EXECUTE NOTIFY-LOWBATT AT ONBATT * EXECUTE NOTIFY-ONBATT AT ONLINE * EXECUTE NOTIFY-ONLINE AT REPLBATT * EXECUTE NOTIFY-REPLBATT AT SHUTDOWN * EXECUTE NOTIFY-SHUTDOWN AT ONBATT * START-TIMER SHUTDOWN 20 AT ONLINE * CANCEL-TIMER SHUTDOWN
 
What does your shutdown script looks like ((cat /bin/upssched-cmd))?
Do you get syslogs when the UPS goes on battery?
 
Ok so got it working. Ended up following the guide on YouTube from Techno Tim. He details how he setup the NUT client on his Promox server. Most of it was similar to what I had, but seemed to use a couple of different folders for config files and lock files.
 
Ok so got it working. Ended up following the guide on YouTube from Techno Tim. He details how he setup the NUT client on his Promox server. Most of it was similar to what I had, but seemed to use a couple of different folders for config files and lock files.
Can you update your configuration with the working ones? That would help further users.
 
Sure. Basically all documented here: https://techno-tim.github.io/posts/NUT-server-guide/

apt install nut-client

nano /etc/nut/upsmon.conf

Code:
RUN_AS_USER root

MONITOR yourups@ip.address.of.nut.server 1 admin secret slave

MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h"
NOTIFYCMD /usr/sbin/upssched
POLLFREQ 2
POLLFREQALERT 1
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower

NOTIFYMSG ONLINE    "UPS %s on line power"
NOTIFYMSG ONBATT    "UPS %s on battery"
NOTIFYMSG LOWBATT   "UPS %s battery is low"
NOTIFYMSG FSD       "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK    "Communications with UPS %s established"
NOTIFYMSG COMMBAD   "Communications with UPS %s lost"
NOTIFYMSG SHUTDOWN  "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT  "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM    "UPS %s is unavailable"
NOTIFYMSG NOPARENT  "upsmon parent process died - shutdown impossible"

NOTIFYFLAG ONLINE   SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT   SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT  SYSLOG+WALL
NOTIFYFLAG FSD      SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK   SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD  SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL
NOTIFYFLAG NOCOMM   SYSLOG+WALL+EXEC
NOTIFYFLAG NOPARENT SYSLOG+WALL

RBWARNTIME 43200

NOCOMMWARNTIME 600

FINALDELAY 5

nano /etc/nut/nut.conf

Code:
MODE=netclient

nano /etc/nut/upssched.conf

Code:
CMDSCRIPT /etc/nut/upssched-cmd
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock

AT ONBATT * START-TIMER onbatt 30
AT ONLINE * CANCEL-TIMER onbatt online
AT ONBATT * START-TIMER earlyshutdown 30
AT LOWBATT * EXECUTE onbatt
AT COMMBAD * START-TIMER commbad 30
AT COMMOK * CANCEL-TIMER commbad commok
AT NOCOMM * EXECUTE commbad
AT SHUTDOWN * EXECUTE powerdown
AT SHUTDOWN * EXECUTE powerdown

nano /etc/nut/upssched-cmd

Code:
#!/bin/sh
 case $1 in
       onbatt)
          logger -t upssched-cmd "UPS running on battery"
          ;;
       earlyshutdown)
          logger -t upssched-cmd "UPS on battery too long, early shutdown"
          /usr/sbin/upsmon -c fsd
          ;;
       shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          /usr/sbin/upsmon -c fsd
          ;;
       upsgone)
          logger -t upssched-cmd "UPS has been gone too long, can't reach"
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac

chmod +x /etc/nut/upssched-cmd

systemctl restart nut-client
 
  • Like
Reactions: gseeley and ualex
I've come across a small issue in the logic of the files.

Last night my Proxmox server shut down because it lost power for 2 seconds. Even though the power returned in 2 seconds, the server still executed a full shutdown.

From checking syslog I found that two timers started when it was briefly on battery. The "on batt" timer and "earlyshutdown" timer. The "on batt" timer was cancelled when the power returned, but the "earlyshutdown" timer continued for 30 seconds before doing a full shutdown.

I found "upssched.conf" had no cancel-timer command for "earlyshutdown", and because of that it would wait 30 seconds and then call the "earlyshutdown" statement in the "upssched-cmd" file (which runs a "-c fsd" command).

So... I commented out references to earlyshutdown in both "upssched.conf" and "upssched-cmd" and added the "/usr/sbin/upsmon -c fsd" command to the "onbatt" statement in "upssched-cmd". I have now tested both turning off power for 10 seconds (servers remains up), and turning off power for 30 seconds, server does a full shutdown.

So files should now look as follows:


upssched-cmd

Code:
#!/bin/sh
 case $1 in
       onbatt)
          logger -t upssched-cmd "UPS running on battery"
          /usr/sbin/upsmon -c fsd
          ;;
       shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          /usr/sbin/upsmon -c fsd
          ;;
       upsgone)
          logger -t upssched-cmd "UPS has been gone too long, can't reach"
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac


upssched.conf

Code:
MDSCRIPT /etc/nut/upssched-cmd
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock

AT ONBATT * START-TIMER onbatt 30
AT ONLINE * CANCEL-TIMER onbatt online
AT LOWBATT * EXECUTE onbatt
AT COMMBAD * START-TIMER commbad 30
AT COMMOK * CANCEL-TIMER commbad commok
AT NOCOMM * EXECUTE commbad
AT SHUTDOWN * EXECUTE powerdown
 
I am having errors with the starting the nut-server . This is since with a fresh proxmox 7.1 install (because I messed up the boot drive), and it was fine with a configuration for nut to activate via snmp. These are the errors when I try do a systemctl start nut-server:

root@X10SLM:~# systemctl start nut-server
Job for nut-server.service failed because the control process exited with error code.
See "systemctl status nut-server.service" and "journalctl -xe" for details.
root@X10SLM:~# systemctl status nut-server.service
● nut-server.service - Network UPS Tools - power devices information server
Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-12-01 14:54:50 +08; 10s ago
Process: 544675 ExecStart=/sbin/upsd (code=exited, status=1/FAILURE)
CPU: 3ms

Dec 01 14:54:50 X10SLM upsd[544675]: listening on ::1 port 3493
Dec 01 14:54:50 X10SLM upsd[544675]: /etc/nut/upsd.conf is world readable
Dec 01 14:54:50 X10SLM upsd[544675]: listening on 127.0.0.1 port 3493
Dec 01 14:54:50 X10SLM upsd[544675]: listening on ::1 port 3493
Dec 01 14:54:50 X10SLM upsd[544675]: Can't open /etc/nut/ups.conf: Can't open /etc/nut/ups.conf: Permission denied
Dec 01 14:54:50 X10SLM upsd[544675]: Network UPS Tools upsd 2.7.4
Dec 01 14:54:50 X10SLM upsd[544675]: Can't open /etc/nut/ups.conf: Can't open /etc/nut/ups.conf: Permission denied
Dec 01 14:54:50 X10SLM systemd[1]: nut-server.service: Control process exited, code=exited, status=1/FAILURE
Dec 01 14:54:50 X10SLM systemd[1]: nut-server.service: Failed with result 'exit-code'.
Dec 01 14:54:50 X10SLM systemd[1]: Failed to start Network UPS Tools - power devices information server.
root@X10SLM:~#

Much appreciated if somehow can show me how to correct this

thank you
 
Are you intending for the Proxmox server to be a client or server for NUT?
 
I am using SNMP as a driver on the APC UPS. So not sure if that means the proxmox server should be server or client
 
With nut you got a server that monitors the UPS, provides statistics about the UPS for all clients and will send a shutdown command to all nut clients in case of an power outage. A nut client will just listen to a nut server.
 
I believe i set the mode to standalone in nut.conf.
What is strange is that I installed it fine previously, but only after I had to redo the proxmox installation did I get these errors
 
Sure...

Out of interest, can you connect it via USB, might make it easier to get working
 
the APC SUA1000 that I am using manual suggest that if I use the AP9617 network card(which I do for the snmp), then i should NOT connect up via USB
 
actually thats exactly how I did it in the link you posted

What I cannot figure out is the error messages that came with a new proxmox install. it was fine with the previous proxmox install (also 7.0)
 
If you mean this error, "Can't open /etc/nut/ups.conf: Permission denied"

Maybe try resetting the permissions on the file? chmod +x /etc/nut/ups.conf
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!