adds apcupsd, thanks Matthias Eller , fixes #2157
[openwrt/svn-archive/archive.git] / net / apcupsd / files / apccontrol
1 #!/bin/sh
2 #
3 # Copyright (C) 1999-2002 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
4 #
5 # for apcupsd release 3.14.1 (04 May 2007) - unknown
6 #
7 # platforms/apccontrol. Generated from apccontrol.in by configure.
8 #
9 # Note, this is a generic file that can be used by most
10 # systems. If a particular system needs to have something
11 # special, start with this file, and put a copy in the
12 # platform subdirectory.
13 #
14
15 #
16 # These variables are needed for set up the autoconf other variables.
17 #
18 prefix=/usr
19 exec_prefix=/usr
20
21 APCPID=/var/run/apcupsd.pid
22 APCUPSD=/usr/sbin/apcupsd
23 SHUTDOWN=/sbin/shutdown
24 SCRIPTSHELL=/bin/sh
25 SCRIPTDIR=/etc/apcupsd
26 WALL=true
27
28 #
29 # Concatenate all output from this script to the events file
30 # Note, the following kills the script in a power fail situation
31 # where the disks are mounted read-only.
32 # exec >>/var/log/apcupsd.events 2>&1
33
34 #
35 # This piece is to substitute the default behaviour with your own script,
36 # perl, or C program.
37 # You can customize every single command creating an executable file (may be a
38 # script or a compiled program) and calling it the same as the $1 parameter
39 # passed by apcupsd to this script.
40 #
41 # After executing your script, apccontrol continues with the default action.
42 # If you do not want apccontrol to continue, exit your script with exit
43 # code 99. E.g. "exit 99".
44 #
45 # WARNING: the apccontrol file will be overwritten every time you update your
46 # apcupsd, doing `make install'. Your own customized scripts will _not_ be
47 # overwritten. If you wish to make changes to this file (discouraged), you
48 # should change apccontrol.sh.in and then rerun the configure process.
49 #
50 if [ -f ${SCRIPTDIR}/${1} -a -x ${SCRIPTDIR}/${1} ]
51 then
52 ${SCRIPTDIR}/${1} ${2} ${3} ${4}
53 # exit code 99 means he does not want us to do default action
54 if [ $? = 99 ] ; then
55 exit 0
56 fi
57 fi
58
59 case "$1" in
60 killpower)
61 echo "Apccontrol doing: ${APCUPSD} --killpower on UPS ${2}"
62 sleep 10
63 ${APCUPSD} --killpower
64 echo "Apccontrol has done: ${APCUPSD} --killpower on UPS ${2}" | ${WALL}
65 ;;
66 commfailure)
67 echo "Warning communications lost with UPS ${2}" | ${WALL}
68 ;;
69 commok)
70 echo "Communications restored with UPS ${2}" | ${WALL}
71 ;;
72 #
73 # powerout, onbattery, offbattery, mainsback events occur
74 # in that order.
75 #
76 powerout)
77 echo "Warning power loss detected on UPS ${2}" | ${WALL}
78 ;;
79 onbattery)
80 echo "Power failure on UPS ${2}. Running on batteries." | ${WALL}
81 ;;
82 offbattery)
83 ;;
84 mainsback)
85 echo "Power has returned on UPS ${2}..." | ${WALL}
86 if [ -f /etc/powerfail ] ; then
87 printf "Continuing with shutdown." | ${WALL}
88 fi
89 ;;
90 failing)
91 echo "Battery power exhaused on UPS ${2}. Doing shutdown." | ${WALL}
92 ;;
93 timeout)
94 echo "Battery time limit exceeded on UPS ${2}. Doing shutdown." | ${WALL}
95 ;;
96 loadlimit)
97 echo "Remaining battery charge below limit on UPS ${2}. Doing shutdown." | ${WALL}
98 ;;
99 runlimit)
100 echo "Remaining battery runtime below limit on UPS ${2}. Doing shutdown." | ${WALL}
101 ;;
102 doreboot)
103 echo "UPS ${2} initiating Reboot Sequence" | ${WALL}
104 ${SHUTDOWN} -r now "apcupsd UPS ${2} initiated reboot"
105 ;;
106 doshutdown)
107 echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
108 ${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown"
109 ;;
110 annoyme)
111 echo "Power problems with UPS ${2}. Please logoff." | ${WALL}
112 ;;
113 emergency)
114 echo "Emergency Shutdown. Possible battery failure on UPS ${2}." | ${WALL}
115 ;;
116 changeme)
117 echo "Emergency! Batteries have failed on UPS ${2}. Change them NOW" | ${WALL}
118 ;;
119 remotedown)
120 echo "Remote Shutdown. Beginning Shutdown Sequence." | ${WALL}
121 ;;
122 restartme)
123 echo -n "Restarting APCUPSD Power Management: "
124 THEPID=`cat ${APCPID}`
125 kill ${THEPID}
126 rm -f ${APCPID}
127 rm -f /etc/powerfail
128 rm -f /etc/nologin
129 sleep 5
130 `${APCUPSD}`
131 echo "apcupsd"
132 ;;
133 startselftest)
134 ;;
135 endselftest)
136 ;;
137 battdetach)
138 ;;
139 battattach)
140 ;;
141 *) echo "Usage: ${0##*/} command"
142 echo " warning: this script is intended to be launched by"
143 echo " apcupsd and should never be launched by users."
144 exit 1
145 ;;
146 esac