packages/net/nut/files/nutshutdown
Daniel F. Dickinson cb06f02504 nut: Prevent FSD when not specifically requested
Under certain circumstances nutshutdown was causing a forced
shutdown of the UPS even though killpower was not indicated.
Prevent that.  Also clarify the logic for powering off server
by avoiding && || chains.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
2019-01-08 04:07:01 -05:00

44 lines
893 B
Bash
Executable file

#!/bin/sh
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
. /lib/functions.sh
mount -o remount,ro /overlay /overlay
mount -o remount,ro / /
stop_instance() {
/etc/init.d/nut-server stop "$1"
}
shutdown_instance() {
local cfg="$1"
config_get driver "$cfg" driver "usbhid-ups"
# Only FSD if killpower was indicated
if [ -f /var/run/killpower ]; then
/lib/nut/${driver} -a "$cfg" -k
fi
}
if [ -f /var/run/killpower ]; then
if [ -f /etc/config/nut_server ]; then
config_load nut_server
# Can't FSD unless drivers are stopped
config_foreach stop_instance driver
# Driver will wait 'offdelay' before shutting down
config_foreach shutdown_instance driver
# So this can happen
poweroff
# And just in case
sleep 120
# Uh-oh failed to poweroff UPS
reboot -f
else
poweroff
fi
else
poweroff
fi