You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB

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