[Nut-upsuser] NUT & UPS, how to shut down client after 2 min on battery?
Matt Kinni
matt at cipixia.com
Sat Dec 31 04:51:34 GMT 2022
On 2022-12-22 05:47, Rafael Reinoso via Nut-upsuser wrote:
> I do not know much about NUT, but after some Googling, one idea I have
> is to in /etc/nut/upsmon.conf on client change to this
>
> |NOTIFYCMD "/etc/nut/shutdown_script.sh" NOTIFYFLAG ONBATT EXEC |
>
> And then in /etc/nut/shutdown_script.sh have something like this
>
Hi Raffe, I had a very similar setup to this for a long time until I
recently changed it; I will describe what I used to do and why I don't
set a timer like this anymore.
In /etc/ups/upsmon.conf (my system is Fedora) I captured three events:
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG LOWBATT SYSLOG+EXEC
NOTIFYCMD /usr/sbin/upssched
The key thing here is I am not calling a bash script directly with
NOTIFYCMD, but delegating it to the built in upssched process which has
timer functionality (and is packaged with nut in Fedora).
In /etc/ups/upssched.conf, the key options are:
CMDSCRIPT /usr/local/bin/upsmon-execscript.sh
AT ONBATT * START-TIMER shutdown_onbatt 600
AT ONLINE * CANCEL-TIMER shutdown_onbatt
As you can see it starts a 10 minute timer, and cancels the timer if
mains power is restored. The bash script is similar to yours, but
benefits from not having to do any time management of its own or count
how long it has been running. upssched does that for you, and simply
calls your script when the listed events occur and with the timer of
your choosing.
Here is the problem with this approach in general:
- what happens if I boot my server while already on battery, and
the battery is low? My script won't do anything for 10 minutes
- what happens if the power repeatedly cycles on/off/on/off?
10 more minutes are granted every time, which again leaves you
in a dangerous situation
My current approach is to have my server turn off when the UPS hits 40%
battery. I have redefined the "lowbatt" signal to a very comfortable
40%, so there is plenty of time to shutdown and still plenty of battery
left for charging other things like my cellphone etc.
The way to accomplish this is in /etc/ups/ups.conf, under your ups
configuration put:
ignorelb
override.battery.charge.low=40
This seems safer to me because it's based on the actual capacity
remaining, and not an arbitrary timer.
Hope this helps, and happy new years!
Matt
More information about the Nut-upsuser
mailing list