Using a QNAP NAS connected to an EATON 3S UPS via USB, I wanted to do the following
In case of power loss:
- Go to UPS Power
- Start Timer
- Abort Timer if Power restored
- After 10 Minutes, shut down Proxmox (using ISCSI Storage provided by QNAP)
- After 15 Minutes, shut down QNAP
For this, I found a solution in the Proxmox forums, that I just want to keep here as well, to ensure redundancy. Original Thread
- install
nut-clientpackage on Proxmox Host - confgure as follows:
/etc/nut/nut.conf
MODE=netclient
/etc/nut/upsmon.conf
RUN_AS_USER root
MONITOR qnapups@xxx.xxx.xxx.xxx 1 admin 123456 secondary
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 is back online"
NOTIFYMSG ONBATT "UPS %s on battery"
NOTIFYMSG LOWBATT "UPS %s battery low"
NOTIFYMSG FSD "UPS %s: forced shutdown in progress"
NOTIFYMSG COMMOK "Communcation to UPS %s reestablished"
NOTIFYMSG COMMBAD "Communication to UPS %s lost"
NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding"
NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced"
NOTIFYMSG NOCOMM "UPS %s unreachable"
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
The admin account is static and provided by QNAP. The password can't be changed apparently.
On QNAP: Remember to add your Proxmox Host(s) to the whitelist!
/etc/nut/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
/etc/nut/upssched-cmd (chmod +x)
#!/bin/sh
case $1 in
onbatt)
logger -t upssched-cmd "UPS on battery"
/usr/sbin/upsmon -c fsd
;;
commbad_message)
echo "UPS disconnected" | mailx -s "Proxmox: UPS Warning" email@example.com
;;
online)
logger -t upssched-cmd "UPS back online"
;;
commok_message)
echo "UPS reconnected" | mailx -s "Proxmox: UPS Warning" email@example.com
;;
nocomm_message)
echo "UPS unreachable" | mailx -s "Proxmox: UPS Warning" email@example.com
;;
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 is being shut down" | mailx -s "Promox: UPS Warning" email@example.com
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
- Restart NUT Service
nut-monitor