/etc/init.d/powerfail is in powstatd 1.5.1-9.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #! /bin/sh
#
# powerfail This script is run when the UPS tells the system the power has
# gone. Tell everybody and start the shutdown based on the
# failure type. This script will also being run when the power
# comes up again.
#
#
# Based on genpower's /etc/init.d/powerfail file:
# Version: v1.2
# Author: Tom Webster <webster@kaiwan.com>
# Modified-By: Brian White <bcwhite@pobox.com>
#
# This is basically a script that embeds the funtionality of powstatd
# scripts as modified from genpower by Peter S. Galbraith <psg@debian.org>
#
failtime=+5 # shutdown delay from initial power failure
lowtime=now # shutdown delay from low-battery warning
failmsg="Power failure: system operating on batteries."
lowmsg="Battery failure -- EMERGENCY SHUTDOWN"
okaymsg="LINE POWER RESTORED -- RESUMING NORMAL OPERATION"
# Set the path.
PATH=/sbin:/etc:/bin:/usr/bin
# Set location of file containing PID of running shutdowns
spidpath="/var/run/shutdown.pid"
# See what happened.
case "$1" in
start)
# Called with a powerfail event, check to see if a shutdown is running
if [ -f $spidpath ]
then
# Shutdown is running, kill it to process the new event
shutdown -c >/dev/null 2>&1
fi
shutdown -h $failtime "$failmsg" &
;;
now)
# Battery is low
# Check to see if a shutdown is running
if [ -f $spidpath ]
then
# Shutdown is running, kill it to process the new event
shutdown -c >/dev/null 2>&1
fi
shutdown -h $lowtime "$lowmsg" &
;;
stop)
# Ok, power is good again. Say so on the console.
if [ -f $spidpath ]
then
# Only cancel if shutdown is running (system boot will call this)
shutdown -c "$okaymsg"
fi
;;
*)
echo "Usage: /etc/init.d/powerfail {start|now|stop}"
echo " start means: shutdown in $failtime minutes due to power failure"
echo " now means: shutdown NOW due to eminent UPS battery failure"
echo " stop means: cancel shutdown before power is back online."
exit 1
;;
esac
exit 0
|