UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / platforms / apccontrol.in
blobd9883244143812ba7bbc1055cc5f1b92b509ecdc
1 #!@SCRIPTSHELL@
3 # Copyright (C) 1999-2002 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
5 #  for apcupsd release @VERSION@ (@DATE@) - @DISTNAME@
7 # @configure_input@
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.
16 # These variables are needed for set up the autoconf other variables.
18 prefix=@prefix@
19 exec_prefix=@exec_prefix@
21 APCPID=@PIDDIR@/apcupsd.pid
22 APCUPSD=@sbindir@/apcupsd
23 SHUTDOWN=@SHUTDOWN@
24 SCRIPTSHELL=@SCRIPTSHELL@
25 SCRIPTDIR=@sysconfdir@
26 WALL=wall
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 >>@LOGDIR@/apcupsd.events 2>&1
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.
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".
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.
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
59 case "$1" in
60     killpower)
61         echo "Apccontrol doing: ${APCUPSD} --killpower on UPS ${2}" | ${WALL}
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     ;;
73 # powerout, onbattery, offbattery, mainsback events occur
74 #   in that order.
76     powerout)
77     ;;
78     onbattery)
79         echo "Power failure on UPS ${2}. Running on batteries." | ${WALL}
80     ;;
81     offbattery)
82         echo "Power has returned on UPS ${2}..." | ${WALL}
83     ;;
84     mainsback)
85         if [ -f @PWRFAILDIR@/powerfail ] ; then
86            printf "Continuing with shutdown."  | ${WALL}
87         fi
88     ;;
89     failing)
90         echo "Battery power exhaused on UPS ${2}. Doing shutdown." | ${WALL}
91     ;;
92     timeout)
93         echo "Battery time limit exceeded on UPS ${2}. Doing shutdown." | ${WALL}
94     ;;
95     loadlimit)
96         echo "Remaining battery charge below limit on UPS ${2}. Doing shutdown." | ${WALL}
97     ;;
98     runlimit)
99         echo "Remaining battery runtime below limit on UPS ${2}. Doing shutdown." | ${WALL}
100     ;;
101     doreboot)
102         echo "UPS ${2} initiating Reboot Sequence" | ${WALL}
103         ${SHUTDOWN} -r now "apcupsd UPS ${2} initiated reboot"
104     ;;
105     doshutdown)
106         echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
107         ${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown"
108     ;;
109     annoyme)
110         echo "Power problems with UPS ${2}. Please logoff." | ${WALL}
111     ;;
112     emergency)
113         echo "Emergency Shutdown. Possible battery failure on UPS ${2}." | ${WALL}
114     ;;
115     changeme)
116         echo "Emergency! Batteries have failed on UPS ${2}. Change them NOW" | ${WALL}
117     ;;
118     remotedown)
119         echo "Remote Shutdown. Beginning Shutdown Sequence." | ${WALL}
120     ;;
121     startselftest)
122     ;;
123     endselftest)
124     ;;
125     battdetach)
126     ;;
127     battattach)
128     ;;
129     *)  echo "Usage: ${0##*/} command"
130         echo "       warning: this script is intended to be launched by"
131         echo "       apcupsd and should never be launched by users."
132         exit 1
133     ;;
134 esac