nut: Make FSD really work
authorDaniel F. Dickinson <cshored@thecshore.com>
Mon, 27 Aug 2018 20:33:25 +0000 (16:33 -0400)
committerDaniel F. Dickinson <cshored@thecshore.com>
Wed, 29 Aug 2018 04:15:14 +0000 (00:15 -0400)
Forced shutdown of the UPS was not actually happening before
due to lack of specific commands doing the shutdown.  This
(and the nut-driver initscript) fix that.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
net/nut/Makefile
net/nut/files/nut-monitor.init
net/nut/files/nut_monitor
net/nut/files/nutshutdown [new file with mode: 0755]

index d5a573ede7727c46cfdbbd7dc78773a06386faf9..9c18b610574505842e720b1210aada4478070a0d 100644 (file)
@@ -169,6 +169,7 @@ define Package/nut-upsmon/install
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/nut-monitor.init $(1)/etc/init.d/nut-monitor
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsmon $(1)/usr/sbin/
+       $(INSTALL_BIN) ./files/nutshutdown $(1)/usr/sbin/nutshutdown
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_CONF) ./files/nut_monitor $(1)/etc/config/nut_monitor
        ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf
index 34bacfb8eac78246beb39c1ff28adc6fb008e794..c406746f5e8fbf49f3c8251a167afe98f705dfba 100755 (executable)
@@ -15,7 +15,7 @@ nut_upsmon_conf() {
        config_get val "$cfg" minsupplies 1
        echo "MINSUPPLIES $val" >> $UPSMON_C
 
-       config_get val "$cfg" shutdowncmd "/sbin/halt"
+       config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown"
        echo "SHUTDOWNCMD \"$val\"" >> $UPSMON_C
 
        config_get val "$cfg" notifycmd
index 1f535b135d33cc97010f7a22078933fbb5b81e79..7dd55ff130c1566e03848a5e426e403d72593021 100644 (file)
@@ -1,7 +1,7 @@
 #config upsmon 'upsmon'
 #      option runas run-as-user
 #      option minsupplies 1
-#      option shutdowncmd /sbin/halt
+#      option shutdowncmd '/usr/sbin/nutshutdown'
 #      option notifycmd /path/to/cmd
 #      list defaultnotify SYSLOG
 #      option pollfreq 5
diff --git a/net/nut/files/nutshutdown b/net/nut/files/nutshutdown
new file mode 100755 (executable)
index 0000000..e4fd962
--- /dev/null
@@ -0,0 +1,41 @@
+#!/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"
+       /lib/nut/${driver} -a "$cfg" -k
+}
+
+[ -f /var/run/killpower ] && {
+       [ -f /etc/config/nut_server ] && {
+               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
+       } || {
+               poweroff
+       }
+} || {
+       poweroff
+}