Debian Codegraph @

heartbeat/AudibleAlarm

raw
1 #!/bin/sh
2 #
3 # Startup script for the Audible Alarm
4 #
5 # author: Kirk Lawson <[email protected]>
6 # Horms <[email protected]>
7 #
8 # description: sets an audible alarm running by beeping at a set interval
9 # processname: alarm
10 # config: /etc/AudibleAlarm/AudibleAlarm.conf - not yet implemented
11 #
12 # OCF parameters are as below:
13 # OCF_RESKEY_nodelist
14 #
15 # License: GNU General Public License (GPL)
16
17 #######################################################################
18 # Source function library.
19 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
20 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
21
22 #######################################################################
23 PIDFILE=${HA_VARRUN}/heartbeat-bell
24 #For testing
25 #PIDFILE=/tmp/heartbeat-bell
26
27 # What host are we running on?
28 us=`uname -n`
29
30 usage() {
31 echo "Usage: $0 {start|stop|restart|status|monitor|meta-data|validate-all}"
32 echo " The node list is an optional space delimited"
33 echo " list of hosts that should never sound the alarm."
34 }
35
36 meta_data() {
37 cat <<END
38 <?xml version="1.0"?>
39 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
40 <resource-agent name="AudibleAlarm" version="1.0">
41 <version>1.0</version>
42
43 <longdesc lang="en">
44 Resource script for AudibleAlarm. It sets an audible alarm running by beeping
45 at a set interval.
46 </longdesc>
47 <shortdesc lang="en">Emits audible beeps at a configurable interval</shortdesc>
48
49 <parameters>
50 <parameter name="nodelist" unique="0">
51 <longdesc lang="en">
52 The node list that should never sound the alarm.
53 </longdesc>
54 <shortdesc lang="en">Node list</shortdesc>
55 <content type="string" default="" />
56 </parameter>
57 </parameters>
58
59 <actions>
60 <action name="start" timeout="10s" />
61 <action name="stop" timeout="10s" />
62 <action name="restart" timeout="10s" />
63 <action name="status" depth="0" timeout="10s" interval="10s" />
64 <action name="monitor" depth="0" timeout="10s" interval="10s" />
65 <action name="meta-data" timeout="5s" />
66 <action name="validate-all" timeout="5s" />
67 </actions>
68 </resource-agent>
69 END
70 }
71
72 audiblealarm_start () {
73 ocf_log info "$0: Starting"
74 if [ -f $PIDFILE ]; then
75 PID=`head -n 1 $PIDFILE`
76 if [ -n "$PID" ]; then
77 ocf_log info "$0: Appears to already be running, killing [$PID]"
78 kill $PID > /dev/null
79 fi
80 fi
81 # Use () to create a subshell to make the redirection be synchronized.
82 ( while [ 1 ]; do
83 sleep 1 #Sleep first, incase we bail out
84 printf "\a" > /dev/console
85 # Uncomment this line to cause floppy drive light
86 # to flash (requires fdutils package).
87 # /usr/bin/floppycontrol --pollstate > /dev/null
88 #
89 # To avoid issues when called by lrmd, redirect stdout->stderr.
90 done &
91 if echo $! > $PIDFILE; then
92 :
93 else
94 ocf_log info "$0: Could not write to pid file \"$PIDFILE\", bailing"
95 kill $!
96 return $OCF_ERR_GENERIC
97 fi) >&2
98
99 return $?
100 }
101
102 audiblealarm_stop () {
103 ocf_log info "$0: Shutting down"
104 if [ -f $PIDFILE ]; then
105 PID=`head -n 1 $PIDFILE`
106 # ocf_log info "$0: Appears to already be running, killing [$PID]"
107 # commented by Phost, since the confusion in the log.
108
109 if [ -n "$PID" ]; then
110 # Donnot remove PIDFILE in case the `kill` fails.
111 kill $PID > /dev/null && rm -f $PIDFILE
112 fi
113 fi
114
115 return $?
116 }
117
118 audiblealarm_restart () {
119 audiblealarm_stop
120 audiblealarm_start
121
122 return $?
123 }
124
125 audiblealarm_status () {
126 if [ -f $PIDFILE ]; then
127 PID=`head -n 1 $PIDFILE`
128 if [ -n "$PID" ]; then
129 echo running
130 return $OCF_SUCCESS
131 fi
132 fi
133
134 echo stopped
135 return $OCF_NOT_RUNNING
136 }
137
138 audiblealarm_validate_all () {
139 check_binary printf
140
141 echo "Validate OK"
142 return $OCF_SUCCESS
143 }
144 if [ $# -ne 1 ]; then
145 usage
146 exit $OCF_ERR_ARGS
147 fi
148
149 case "$1" in
150 meta-data)
151 meta_data
152 exit $OCF_SUCCESS
153 ;;
154 start)
155 for arg in $OCF_RESKEY_nodelist
156 do
157 if [ "$us" = "$arg" ]; then
158 # We should not start because we are on a host
159 # listed in our argument list.
160 exit $OCF_SUCCESS
161 fi
162 done
163 audiblealarm_start
164 ;;
165 stop)
166 audiblealarm_stop
167 ;;
168 restart)
169 audiblealarm_restart
170 ;;
171 status|monitor)
172 audiblealarm_status
173 ;;
174 validate-all)
175 audiblealarm_validate_all
176 ;;
177 usage)
178 usage
179 exit $OCF_SUCCESS
180 ;;
181
182 *)
183 usage
184 exit $OCF_ERR_ARGS
185 ;;
186 esac
187
188 exit $?