[SOLVED] NUT Client configuration -> help needed for shutdown Proxmox host

Ronny1978

Member
Mar 13, 2023
62
14
8
Hello Together.

I hope you can help me?

I meet the following requirements:

- Synology DS918+ as NUT Server
- Proxmox host as NUT Client
- APC 1000 with USB connection to Synology DS918+

What works?

- the connection between DS918+ and Proxmox host is established and works
- sending emails from Proxmox host, when NUT connection is lost, established, on batt or online again

What doesn't works?

I want to shut down Proxmox host with "upsmon -c fsd" after 180 seconds after change to ONBATT, but the script doesn't starts. If I execute "upsmon -c fsd" in the Proxmox shell for testing, it works fine. So I think I have a problem with the upssched-cmd. Here me configurations:

nut.conf
Code:
MODE=netclient

upsmon.conf
Code:
RUN_AS_USER root
MONITOR ups@192.168.1.20 1 monuser Secret slave
NOTIFYCMD /etc/nut/notify

MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower

NOTIFYMSG ONLINE        "UPS %s ist wieder Online"
NOTIFYMSG ONBATT        "UPS %s ist im Akkumodus"
NOTIFYMSG LOWBATT       "UPS %s Batterie ist niedrig"
NOTIFYMSG FSD           "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK        "Kommunikation mit UPS %s ist wieder hergestellt"
NOTIFYMSG COMMBAD       "Kommunikation mit UPS %s unterbrochen"
NOTIFYMSG SHUTDOWN      "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT      "UPS %s Batterie muss ersetzt werden"
NOTIFYMSG NOCOMM        "UPS %s ist nicht erreichbar"
NOTIFYMSG NOPARENT      "upsmon Prozess  - shutdown ist unmöglich"

ONLINE   : UPS is back online
ONBATT   : UPS is on battery
LOWBATT  : UPS has a low battery (if also on battery, it's "critical")
FSD      : UPS is being shutdown by the master (FSD = "Forced Shutdown")
COMMOK   : Communications established with the UPS
COMMBAD  : Communications lost to the UPS
SHUTDOWN : The system is being shutdown
REPLBATT : The UPS battery is bad and needs to be replaced
NOCOMM   : A UPS is unavailable (can't be contacted for monitoring)
NOPARENT : The process that shuts down the system has died (shutdown impossible)


NOTIFYFLAG ONLINE       SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT       SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT      SYSLOG+WALL+EXEC
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
NOTIFYFLAG NOPARENT     SYSLOG+WALL

RBWARNTIME 43200

NOCOMMWARNTIME 180

FINALDELAY 5

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

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

upssched-cmd
Code:
#!/bin/sh
case $1 in
onbatt)
logger -t upssched-cmd "UPS running on battery"
/usr/sbin/upsmon -c fsd
;;
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

For your help many thanks in advance. Have a nice weekend and please stay healthy.

Ronny
Chemnitz / Germany
 
Hi / Guten tag.
So did you figure out how to run the script for shutdown ? And was it one to close all vm first and the shutdown prox after ?
 
So did you figure out how to run the script for shutdown ? And was it one to close all vm first and the shutdown prox after ?
Yes. The script shutdown all VM's and LXC containers first, then Proxmox shutdown itself. My Synology DS918+ send a wake on LAN command, when the power is replaced. Proxmox send me an email for each step -> (1. Warning shutdown / 2. Shutdown / 3. Lost communication battery / 4. Communication battery rebuild).

It works fine.

Have a nice weekend.

Ronny
 
@Ronny1978 Did you do any further modification to your script? I get the notification that my ups is on battery in sysylog but my proxmox does not shutdown.

Thanks
 
UPSMON.conf
Code:
RUN_AS_USER root
MONITOR ups@ip address NAS 1 monuser 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 ist wieder online"
NOTIFYMSG ONBATT    "UPS %s ist im Akkumodus"
NOTIFYMSG LOWBATT   "UPS %s Batterie ist niedrig"
NOTIFYMSG FSD       "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK    "Kommunikation mit UPS %s wieder hergestellt"
NOTIFYMSG COMMBAD   "Kommunikation mit UPS %s verloren"
NOTIFYMSG SHUTDOWN  "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT  "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM    "UPS %s ist nicht erreichbar"
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

UPSSCHED.conf

Code:
GNU nano 5.4                                                             upssched.conf                                                                     
CMDSCRIPT /etc/nut/upssched-cmd
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock

AT ONBATT * START-TIMER onbatt 600
AT ONLINE * CANCEL-TIMER onbatt online
AT LOWBATT * EXECUTE onbatt
AT COMMBAD * EXECUTE commbad_message
AT COMMOK * EXECUTE commok_message
AT NOCOMM * EXECUTE nocomm_message
AT SHUTDOWN * EXECUTE shutdown_message
AT SHUTDOWN * EXECUTE powerdown

UPSSCHED CMD
Code:
  GNU nano 5.4                                                             upssched-cmd                                                                       
#!/bin/sh

 case $1 in
       onbatt)
          logger -t upssched-cmd "UPS im Akkumodus"
          /usr/sbin/upsmon -c fsd
          ;;
        commbad_message)
          echo "UPS ist nicht mehr verbunden" | mailx -s "Proxmox: UPS Warnmeldung" e-mail address for warning
          ;;
        online)
          logger -t upssched-cmd "UPS wieder Online"
          ;;
        commok_message)
          echo "UPS ist wieder verbunden" | mailx -s "Proxmox: UPS Warnmeldung" e-mail address for warning
          ;;
        nocomm_message)
          echo "UPS ist nicht mehr erreichbar" | mailx -s "Proxmox: UPS Warnmeldung" e-mail address for warning
          ;;
        shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          ;;
        upsgone)
          logger -t upssched-cmd "UPS has been gone too long, can't reach"
          ;;
        shutdown_message)
          echo "Proxmox wird heruntergefahren" | mailx -s "Promox: UPS Warnmeldung" e-mail address for warning
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac

Thats work for me.
 
I've modified upssched-cmd so that it automatically uses the root email address and puts the hostname of the Proxmox host in the subject.

Code:
#!/bin/sh

EMAIL=`cat /etc/pve/user.cfg | grep root | awk '{split($0,a,":"); print a[7]}'`
PROXMOXHOST=$(uname -n)

 case $1 in
       onbatt)
          logger -t upssched-cmd "UPS on battery"
          /usr/sbin/upsmon -c fsd
          ;;
        commbad_message)
          echo "UPS is not connected" | mailx -s "Proxmox ($PROXMOXHOST): UPS Warning" $EMAIL
          ;;
        online)
          logger -t upssched-cmd "UPS Online"
          ;;
        commok_message)
          echo "UPS is connected again" | mailx -s "Proxmox ($PROXMOXHOST): UPS Warning" $EMAIL
          ;;
        nocomm_message)
          echo "UPS is not reachable" | mailx -s "Proxmox ($PROXMOXHOST): UPS Warning" $EMAIL
          ;;
        shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          ;;
        upsgone)
          logger -t upssched-cmd "UPS has been gone too long, can't reach"
          ;;
        shutdown_message)
          echo "Proxmox shutdown" | mailx -s "Promox ($PROXMOXHOST): UPS Warning" $EMAIL
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac
 
Thanks for the configuration examples as well as the upssched-cmd examples - that's very helpful (and kinda unexpected that the defaults aren't more... sane/helpful).

Anyways, i kinda got the same setup around here - Synology is the master, connected via USB cable to a Cyberpower UPS.

Question is, if anyone has recommendations how to handle the shutdown order in a 3-server setup with Ceph?

I mean, i can power down one of three without much of a problem - but after that - is there a preferred sequence? Timeouts to configure? Something? :)

Thanks!
 
Yes. The script shutdown all VM's and LXC containers first, then Proxmox shutdown itself. My Synology DS918+ send a wake on LAN command, when the power is replaced. Proxmox send me an email for each step -> (1. Warning shutdown / 2. Shutdown / 3. Lost communication battery / 4. Communication battery rebuild).

It works fine.

Have a nice weekend.

Ronny
Hello. And how this is implemented can be found in more detail: My Synology DS918+ send a wake on LAN command, when the power is replaced
 
Hello @sany_ch ,

I don't know, if I understand you correctly. When the DS918+ has replaced power and starts, after startup it sends via script the following command to proxmox:

Code:
/usr/syno/sbin/synonet --wake 00:e0:4c:88:0d:80 ovs_bond0
 
  • Like
Reactions: sany_ch
When the DS918+ has replaced power and starts
Not sure of use-case scenario, but surely the Synology device has also been (safely) powered down due to a power failure, what brings the Synology device backup automatically, when power has been restored? More likely you want a box-system/OS that isn't affected by sudden loss of power & can be set to always be/turn-back on when power is online. Don't think Synology device cuts the deal.
 
Last edited:
Don't think Synology device cuts the deal.
It does ;-). The Synology gets the information from the USV via USB. Then its send a signal to my Proxmox to shutdown. If the power is replaced, the Synology starts up and starts a script -> WoL to Proxmox Host. Promox started also. It works very well.
 
  • Like
Reactions: gfngfn256

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!