nut on Debian bullseye: issues with UID and default config
Hello,
I run a nut-server & nut-client on Debian bullseye connected to an UPS.
It works very well: there are syslog messages for when the current is
down and it's on battery, I can see the various statistics with upsc.
However, it does not seem it really shuts down when low on battery.
I noticed that upsmon & upssched run under user nut, not root, so
upsmon.conf's SHUTDOWNCMD "/sbin/shutdown -h +0" does not work.
As a work-around I installed sudo and added this to /etc/sudoers:
nut ALL=(root) NOPASSWD: /root/scripts/all-machines-shutdown.sh
and configured "sudo /root/scripts/all-machines-shutdown.sh" as the
above SHUTDOWNCMD definition.
This script is a bit complex because it needs to stop various machines
in the correct order, but so far it looks ok.
However, I noticed that sometimes the time to do the complete shutdown
is quite long and when the batteries start to get a bit older,
it could mean there is not enough time till the battery is completely
depleted.
So I modified upsmon.conf so to use upssched to start the shutdown
after a three minutes of "on battery" has passed (in my region, either
the cut is 10 seconds or less, or it's a few hours anyway).
This gives, in upsmon.conf:
NOTIFYCMD /sbin/upssched
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG LOWBATT SYSLOG+EXEC
and in upssched.conf:
CMDSCRIPT /usr/local/bin/upssched-cmd-special
AT ONBATT * START-TIMER onbattwarn 180
AT ONLINE * CANCEL-TIMER onbattwarn
AT ONBATT * EXECUTE onbatt
AT ONLINE * EXECUTE onpower
AT REPLBATT * EXECUTE replace_batt
and in /usr/local/bin/upssched-cmd-special, something like:
case $1 in
onbattwarn) logger -t $0 "should shutdown $(id)"
sudo /root/scripts/all-machines-shutdown.sh
;;
onbatt|onpower|replace_batt) logger -t $0 "$1 $(id)" ;;
*)
logger -t $0 "Unrecognized command: $1"
;;
esac
I also noticed that without the sudo it does not work either.
However, there is more: if I do not change, in upssched.conf two
definitions to:
PIPEFN /run/nut/upssched.pipe
LOCKFN /run/nut/upssched.lock
it fails because it looks the startup scripts do not create the
/run/nut/upssched/ directory which seems referenced by the default
configuration.
I just checked, and the stock nut-server and nut-client packages from
bullseye still have those default configurations. I do not have
a system managing an UPS running bookworm yet.
So, either this post will be a documentation helping others, or an
expert could tell me what I did wrong in the above :)
Reply to: