nut-debian/scripts/systemd/nutshutdown.in
2022-07-10 09:23:45 +02:00

24 lines
709 B
Bash
Executable File

#!/bin/sh
# This script requires both nut-server (drivers)
# and nut-client (upsmon) to be present locally
# and on mounted filesystems
[ -x "@SBINDIR@/upsmon" ] && [ -x "@SBINDIR@/upsdrvctl" ] || exit
if @SBINDIR@/upsmon -K >/dev/null 2>&1; then
# The argument may be anything compatible with sleep
# (not necessarily a non-negative integer)
wait_delay="`/bin/sed -ne 's#^ *POWEROFF_WAIT= *\(.*\)$#\1#p' @CONFPATH@/nut.conf`" || wait_delay=""
@SBINDIR@/upsdrvctl shutdown
if [ -n "$wait_delay" ] ; then
/bin/sleep $wait_delay
# We need to pass --force twice here to bypass systemd and execute the
# reboot directly ourself.
/bin/systemctl reboot --force --force
fi
fi
exit 0