blob: 7270f983f1088e90b72dae4ca00e2e8dd9bc4370 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2#
3# This is free software, licensed under the GNU General Public License v2.
4# See /LICENSE for more information.
5#
6
7stop_instance() {
8 /etc/init.d/nut-server stop "$1"
9}
10
11shutdown_instance() {
12 local cfg="$1"
13 config_get driver "$cfg" driver "usbhid-ups"
14
15 # Only FSD if killpower was indicated
16 if [ -f /var/run/killpower ]; then
17 /lib/nut/"${driver}" -a "$cfg" -k
18 fi
19}
20
21do_fsd() {
22 if [ -f /var/run/killpower ]; then
23 # Only make FS readonly if we are doing an FSD
24 mount -o remount,ro /overlay /overlay
25 mount -o remount,ro / /
26
27 . ${IPKG_INSTROOT}/lib/functions.sh
28
29 if [ -f /etc/config/nut_server ]; then
30 config_load nut_server
31
32 # Can't FSD unless drivers are stopped
33 config_foreach stop_instance driver
34 # Driver will wait 'offdelay' before shutting down
35 config_foreach shutdown_instance driver
36 # So this can happen
37 rm -f /var/run/killpower
38 poweroff
39 # And just in case
40 sleep 120
41 # Uh-oh failed to poweroff UPS
42 reboot -f
43 else
44 poweroff
45 fi
46 else
47 poweroff
48 fi
49}
50
51do_fsd