File: genpowerfail

package info (click to toggle)
genpower 1.0.1-13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 264 kB
  • ctags: 44
  • sloc: ansic: 522; sh: 183; makefile: 109
file content (71 lines) | stat: -rwxr-xr-x 2,170 bytes parent folder | download | duplicates (6)
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
#! /bin/sh
#
# genpowerfail	This script is run when the UPS tells the system
#		the power has gone. Tell everybody, ans start the 
#		shutdown based on the failure type.                
#		This script is also being run when the power comes
#		up again (if it does in time!)
#
# Version:	/etc/genpowerfail 1.0.1
#
# Author:	Tom Webster <webster@kaiwan.com>
#

# Set the path.
PATH=/sbin:/etc:/bin:/usr/bin

# Set location of upsstatus file
statpath="/etc/upsstatus"

# Set location of file containing PID of running shutdowns
spidpath="/etc/shutdownpid"

# See what happened.
case "$1" in
	start)
		# Called with a powerfail event, check to see if a shutdown is running, and stop it if it is.
		if [ -f $spidpath ]
		then
			# Shutdown is running, kill it to process the new event
			shutdown -c "Halting running shutdown to process power event...."
		fi

		# Get power problem and act on it
		if [ -r $statpath ]
		then
	                stats=`head -1 $statpath`
			case "$stats" in
				FAIL)  # Power is down
                                	shutdown -r +2 "THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
					;;
				SCRAM) # Battery is low
					shutdown -r now "THE POWER IS DOWN! BATTERY POWER IS LOW!  EMERGENCY SHUTDOWN!" < /dev/console &
					;;
				CABLE) # Possible bad cable
 	                                shutdown -r +1 "POSSIBLE BAD CABLE! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
					;;
                                *)     # Unknown message, assume power is down
                                        shutdown -r +2 "THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
                                        ;;

			esac
		else
			# genowerfail called, and upsstatus dosen't exist.
			# Assume user is using powerd, and shutdown.
			shutdown -r +2 "THE POWER IS DOWN! SHUTTING DOWN SYSTEM! PLEASE LOG OFF NOW!" < /dev/console &
 
		fi
		;;
  	stop)
		# Ok, power is good again. Say so on the console.
		#echo "THE POWER IS BACK, GOING MULTI USER"

		shutdown -c "THE POWER IS BACK"
		;;
  	*)
		echo "Usage: /etc/genpowerfail {start|stop}"
		exit 1
		;;
  esac

  exit 0