Table of Contents |
---|
Overview
Shutdown design
When your UPS batteries get low, the operating system needs to be brought down cleanly. Also, the UPS load should be turned off so that all devices that are attached to it are forcibly rebooted.
Here are the steps that occur when a critical power event happens:
- The UPS goes on battery
The UPS reaches low battery (a "critical" UPS), that is to say upsc displays:
ups.status: OB LB
The exact behavior depends on the specific device, and is related to:
- battery.charge and battery.charge.low
- battery.runtime and battery.runtime.low
The upsmon master notices and sets "FSD" - the "forced shutdown" flag to tell all slave systems that it will soon power down the load.
(If you have no slaves, skip to step 6)
upsmon slave systems see "FSD" and:
- generate a NOTIFY_SHUTDOWN event
- wait FINALDELAY seconds - typically 5
- call their SHUTDOWNCMD
- disconnect from upsd
- The upsmon master system waits up to HOSTSYNC seconds (typically 15) for the slaves to disconnect from upsd. If any are connected after this time, upsmon stops waiting and proceeds with the shutdown process.
The upsmon master:
- generates a NOTIFY_SHUTDOWN event
- waits FINALDELAY seconds - typically 5
- creates the POWERDOWNFLAG file - usually /etc/killpower
- calls the SHUTDOWNCMD
- On most systems, init takes over, kills your processes, syncs and unmounts some filesystems, and remounts some read-only.
- init then runs your shutdown script. This checks for the POWERDOWNFLAG, finds it, and tells the UPS driver(s) to power off the load.
- The system loses power.
- Time passes. The power returns, and the UPS switches back on.
- All systems reboot and go back to work.
...
- upsname = qnapups
- user = deepthought
- password = 123456
Setup Timer to Shutdown after 1 Minute
Edit the upssched.conf file
Code Block |
---|
$ sudo vi /etc/nut/upssched.conf |
Ensure that the CMDSCRIPT is set
Code Block |
---|
CMDSCRIPT /bin/upssched-cmd |
Add the following
Code Block |
---|
# Timer to shutdown machine after 60 seconds
AT ONBATT * START-TIMER onbattwarn 60
AT ONLINE * CANCEL-TIMER onbattwarn |
Edit the Command Script
Code Block |
---|
$ sudo vi /bin/upssched-cmd |
Code Block |
---|
case $1 in
onbattwarn)
logger -t upssched-cmd "Timer On Battery Warning has been triggered - Shutting Down!"
wall "Shutting down in 30 seconds!"
shutdown -h `date --date "now + 30 seconds"`
shutdown -h now
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
|
Restart Nut Client
Restart nut client:
...