nut: Handle FSD properly

Make sure we force shutdown of UPS only when we should, and when
we should that shutdown happens.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
Daniel F. Dickinson
2019-08-27 00:56:42 -04:00
parent a2ab989c12
commit 361e6aaaab
+21 -11
View File
@@ -4,11 +4,6 @@
# See /LICENSE for more information. # See /LICENSE for more information.
# #
. /lib/functions.sh
mount -o remount,ro /overlay /overlay
mount -o remount,ro / /
stop_instance() { stop_instance() {
/etc/init.d/nut-server stop "$1" /etc/init.d/nut-server stop "$1"
} }
@@ -16,11 +11,22 @@ stop_instance() {
shutdown_instance() { shutdown_instance() {
local cfg="$1" local cfg="$1"
config_get driver "$cfg" driver "usbhid-ups" config_get driver "$cfg" driver "usbhid-ups"
/lib/nut/${driver} -a "$cfg" -k
# Only FSD if killpower was indicated
if [ -f /var/run/killpower ]; then
/lib/nut/"${driver}" -a "$cfg" -k
fi
} }
[ -f /var/run/killpower ] && { do_fsd() {
[ -f /etc/config/nut_server ] && { if [ -f /var/run/killpower ]; then
# Only make FS readonly if we are doing an FSD
mount -o remount,ro /overlay /overlay
mount -o remount,ro / /
. ${IPKG_INSTOOT}/lib/functions.sh
if [ -f /etc/config/nut_server ]; then
config_load nut_server config_load nut_server
# Can't FSD unless drivers are stopped # Can't FSD unless drivers are stopped
@@ -28,14 +34,18 @@ shutdown_instance() {
# Driver will wait 'offdelay' before shutting down # Driver will wait 'offdelay' before shutting down
config_foreach shutdown_instance driver config_foreach shutdown_instance driver
# So this can happen # So this can happen
rm -f /var/run/killpower
poweroff poweroff
# And just in case # And just in case
sleep 120 sleep 120
# Uh-oh failed to poweroff UPS # Uh-oh failed to poweroff UPS
reboot -f reboot -f
} || { else
poweroff poweroff
} fi
} || { else
poweroff poweroff
fi
} }
do_fsd