aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/mgeupsd/files/powerhandler
blob: 5f47600d4ebc4ae4761891f5692556db2795b583 (plain) (blame)
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
#!/bin/sh

PATH=${PATH}:/sbin:/usr/sbin:/usr/local/sbin;export PATH

STATUS=`cat ${1}`
L="logger -i -t powerhandler"

${L} "Status message received: ${STATUS}"

if [ "X${STATUS}" = "XFAIL" ]
then
	${L} "Power loss detected, initiating shutdown"
	# we are shutting down... give users some warning
	shutdown -h +5 "POWER FAILURE DETECTED... initiating emergency shutdown... SAVE YOUR WORK NOW AND LOGOFF!!!"
elif [ "X${STATUS}" = "XLOWBATT" ]
then
	${L} "Battery is critical, initiating IMMEDIATE shutdown"
	# battery is low.. shut down NOW!
	# first nix any shutdown processes
	killall shutdown
	shutdown -h now "BATTERY IS LOW... SHUTTING DOWN **IMMEDIATELY**..."
elif [ "X${STATUS}" = "XOK" ]
then
	${L} "Power has been restored, canceling shutdown"
	# everything's ok... cancel the shutdown
	killall shutdown
	rm -f /var/run/nologin
	wall << _EOF_
System power has been restored.
The shutdown procedure has been canceled.
_EOF_
else
	# unknown state... help!
	${L} "this shouldn't be happening!"
	exit 1
fi