Debian Codegraph @

heartbeat/VIPArip

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 #
3 # License: GNU General Public License (GPL)
4 # Support: [email protected]
5 # Author: Huang Zhen <[email protected]>
6 # Copyright (c) 2006 International Business Machines
7 #
8 # Virtual IP Address by RIP2 protocol.
9 # This script manages IP alias in different subnet with quagga/ripd.
10 # It can add an IP alias, or remove one.
11 #
12 # The quagga package should be installed to run this RA
13 #
14 # usage: $0 {start|stop|status|monitor|validate-all|meta-data}
15 #
16 # The "start" arg adds an IP alias.
17 # Surprisingly, the "stop" arg removes one. :-)
18 #
19 # OCF parameters are as below
20 # OCF_RESKEY_ip The IP address in different subnet
21 # OCF_RESKEY_nic The nic for broadcast the route information
22 #
23 #######################################################################
24 # Initialization:
25
26 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
27 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
28
29 RIPDCONF=$HA_RSCTMP/VIPArip-ripd.conf
30 ZEBRA=/usr/sbin/zebrascip-shell filesystem . . `/usr/sbin/zebra`.
31 RIPD=/usr/sbin/ripdscip-shell filesystem . . `/usr/sbin/ripd`.
32 USAGE="usage: $0 {start|stop|status|monitor|validate-all|meta-data}";
33
34 # Parameter defaults
35
36 OCF_RESKEY_ip_default=""
37 OCF_RESKEY_nic_default="eth0"
38 OCF_RESKEY_zebra_binary_default="${ZEBRA}"
39 OCF_RESKEY_ripd_binary_default="${RIPD}"
40
41 : ${OCF_RESKEY_ip=${OCF_RESKEY_ip_default}}
42 : ${OCF_RESKEY_nic=${OCF_RESKEY_nic_default}}
43 : ${OCF_RESKEY_zebra_binary=${OCF_RESKEY_zebra_binary_default}}
44 : ${OCF_RESKEY_ripd_binary=${OCF_RESKEY_ripd_binary_default}}
45
46 #######################################################################
47
48 meta_datascip-shell shell shell-project 0.0.0 meta_data().() {
49 catscip-shell system . . cat. <<END
50 <?xml version="1.0"?>
51 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
52 <resource-agent name="VIPArip" version="1.0">
53 <version>1.0</version>
54
55 <longdesc lang="en">
56 Virtual IP Address by RIP2 protocol.
57 This script manages IP alias in different subnet with quagga/ripd.
58 It can add an IP alias, or remove one.
59 </longdesc>
60 <shortdesc lang="en">Manages a virtual IP address through RIP2</shortdesc>
61
62 <parameters>
63
64 <parameter name="ip" unique="1" required="1">
65 <longdesc lang="en">
66 The IPv4 address in different subnet, for example "192.168.1.1".
67 </longdesc>
68 <shortdesc lang="en">The IP address in different subnet</shortdesc>
69 <content type="string" default="${OCF_RESKEY_ip_default}" />
70 </parameter>
71
72 <parameter name="nic" unique="0">
73 <longdesc lang="en">
74 The nic for broadcast the route information.
75 The ripd uses this nic to broadcast the route information to others
76 </longdesc>
77 <shortdesc lang="en">The nic for broadcast the route information</shortdesc>
78 <content type="string" default="${OCF_RESKEY_nic_default}"/>
79 </parameter>
80
81 <parameter name="zebra_binary" unique="0">
82 <longdesc lang="en">
83 Absolute path to the zebra binary.
84 </longdesc>
85 <shortdesc lang="en">zebra binary</shortdesc>
86 <content type="string" default="${OCF_RESKEY_zebra_binary_default}"/>
87 </parameter>
88
89 <parameter name="ripd_binary" unique="0">
90 <longdesc lang="en">
91 Absolute path to the ripd binary.
92 </longdesc>
93 <shortdesc lang="en">ripd binary</shortdesc>
94 <content type="string" default="${OCF_RESKEY_ripd_binary_default}"/>
95 </parameter>
96
97 </parameters>
98
99 <actions>
100 <action name="start" timeout="20s" />
101 <action name="stop" timeout="20s" />
102 <action name="monitor" depth="0" timeout="20s" interval="5s" />
103 <action name="validate-all" timeout="20s" />
104 <action name="meta-data" timeout="5s" />
105 </actions>
106 </resource-agent>
107 END
108 exit $OCF_SUCCESS
109 }
110
111 usagescip-shell shell shell-project 0.0.0 usage().() {
112 echoscip-shell system . . echo. $USAGE >&2
113 }
114
115 new_config_filescip-shell shell shell-project 0.0.0 new_config_file().() {
116 echoscip-shell system . . echo. new_config_file $1 $2 $3
117 catscip-shell system . . cat. >$RIPDCONF <<END
118 hostname ripd
119 password zebra
120 debug rip events
121 debug rip packet
122 debug rip zebra
123 log file /var/log/quagga/quagga.log
124 router rip
125 !nic_tag
126 no passive-interface $2
127 network $2
128 distribute-list private out $2
129 distribute-list private in $2
130 !metric_tag
131 redistribute connected metric $3
132 !ip_tag
133 access-list private permit $1/32
134 access-list private deny any
135 END
136 }
137 check_paramsscip-shell shell shell-project 0.0.0 check_params().() {
138 if [scip-shell system . . `[`. x"$OCF_RESKEY_ip" = x ]
139 then
140 ocf_log err "ip is a required parameter"
141 exit $OCF_ERR_CONFIGURED
142 fi
143 }
144 set_metricscip-shell shell shell-project 0.0.0 set_metric().() {
145 echoscip-shell system . . echo. set_metric $1
146 sedscip-shell system . . sed. "s/redistribute connected metric .*/redistribute connected metric $1/g" $RIPDCONF > $RIPDCONF.tmp
147 cpscip-shell system . . cp. $RIPDCONF.tmp $RIPDCONF
148 }
149
150 add_ipscip-shell shell shell-project 0.0.0 add_ip().() {
151 echoscip-shell system . . echo. add_ip $1
152 sedscip-shell system . . sed. "s/ip_tag/ip_tag\naccess-list private permit $1\/32/g" $RIPDCONF > $RIPDCONF.tmp
153 cpscip-shell system . . cp. $RIPDCONF.tmp $RIPDCONF
154 }
155
156 del_ipscip-shell shell shell-project 0.0.0 del_ip().() {
157 echoscip-shell system . . echo. del_ip $1
158 sedscip-shell system . . sed. "/$1/d" $RIPDCONF > $RIPDCONF.tmp
159 cpscip-shell system . . cp. $RIPDCONF.tmp $RIPDCONF
160 if $GREP "access-list private permit" $RIPDCONF>/dev/nullscip-shell filesystem . . `/dev/null`.
161 then
162 echoscip-shell system . . echo. some other IP is running
163 reload_configscip-shell shell shell-project 0.0.0 reload_config().
164 else
165 stop_quaggascip-shell shell shell-project 0.0.0 stop_quagga().
166 echoscip-shell system . . echo. remove $RIPDCONF
167 rmscip-shell system . . rm. $RIPDCONF
168 fi
169
170 }
171
172 add_nicscip-shell shell shell-project 0.0.0 add_nic().() {
173 echoscip-shell system . . echo. add_nic $1
174 if $GREP "network $1" $RIPDCONF >/dev/nullscip-shell filesystem . . `/dev/null`.
175 then
176 echoscip-shell system . . echo. the nic is already in the config file
177 else
178 sedscip-shell system . . sed. "s/nic_tag/nic_tag\n no passive-interface $1\n network $1\n distribute-list private out $1\n distribute-list private in $1/g" $RIPDCONF > $RIPDCONF.tmp
179 cpscip-shell system . . cp. $RIPDCONF.tmp $RIPDCONF
180 fi
181 }
182
183 reload_configscip-shell shell shell-project 0.0.0 reload_config().() {
184 echoscip-shell system . . echo. reload_config
185 echoscip-shell system . . echo. $RIPDCONF:
186 catscip-shell system . . cat. $RIPDCONF
187 echoscip-shell system . . echo. killall -SIGHUP ripd
188 killall -SIGHUP ripd
189 }
190
191 start_quaggascip-shell shell shell-project 0.0.0 start_quagga().() {
192 echoscip-shell system . . echo. start_quagga
193 echoscip-shell system . . echo. $RIPDCONF:
194 catscip-shell system . . cat. $RIPDCONF
195 echoscip-shell system . . echo. $ZEBRA -d
196 $ZEBRA -d
197 echoscip-shell system . . echo. $RIPD -d -f $RIPDCONF
198 $RIPD -d -f $RIPDCONF
199 }
200
201 stop_quaggascip-shell shell shell-project 0.0.0 stop_quagga().() {
202 echoscip-shell system . . echo. stop_quagga
203 echoscip-shell system . . echo. $RIPDCONF:
204 catscip-shell system . . cat. $RIPDCONF
205 echoscip-shell system . . echo. killall -SIGTERM ripd
206 killall -SIGTERM ripd
207 echoscip-shell system . . echo. killall -SIGTERM zebra
208 killall -SIGTERM zebra
209 }
210
211 start_rip_ipscip-shell shell shell-project 0.0.0 start_rip_ip().() {
212 echoscip-shell system . . echo. start_rip_ip
213 check_paramsscip-shell shell shell-project 0.0.0 check_params().
214
215 if [scip-shell system . . `[`. x"$OCF_RESKEY_nic" = x ]
216 then
217 echoscip-shell system . . echo. OCF_RESKEY_nic is null, set to ${OCF_RESKEY_nic_default}
218 OCF_RESKEY_nic="${OCF_RESKEY_nic_default}"
219 fi
220
221 status_rip_ipscip-shell shell shell-project 0.0.0 status_rip_ip().
222 case $? in
223 $OCF_SUCCESS)
224 ocf_log info "already running"
225 exit $OCF_SUCCESS
226 ;;
227 $OCF_NOT_RUNNING)
228 ;;
229 *)
230 ocf_log info "state undefined, stopping first"
231 stop_rip_ipscip-shell shell shell-project 0.0.0 stop_rip_ip().
232 ;;
233 esac
234
235 $IP2UTIL addr add $OCF_RESKEY_ip/32 dev lo
236 if [scip-shell system . . `[`. -f "$RIPDCONF" ]
237 then
238 # there is a config file, add new data(IP,nic,metric)
239 # to the existing config file.
240 add_ipscip-shell shell shell-project 0.0.0 add_ip(). $OCF_RESKEY_ip
241 add_nicscip-shell shell shell-project 0.0.0 add_nic(). $OCF_RESKEY_nic
242 set_metricscip-shell shell shell-project 0.0.0 set_metric(). 1
243 reload_configscip-shell shell shell-project 0.0.0 reload_config().
244 echoscip-shell system . . echo. sleep 3
245 sleepscip-shell system . . sleep. 3
246 set_metricscip-shell shell shell-project 0.0.0 set_metric(). 3
247 reload_configscip-shell shell shell-project 0.0.0 reload_config().
248 else
249 new_config_filescip-shell shell shell-project 0.0.0 new_config_file(). $OCF_RESKEY_ip $OCF_RESKEY_nic 1
250 start_quaggascip-shell shell shell-project 0.0.0 start_quagga().
251 echoscip-shell system . . echo. sleep 3
252 sleepscip-shell system . . sleep. 3
253 set_metricscip-shell shell shell-project 0.0.0 set_metric(). 3
254 reload_configscip-shell shell shell-project 0.0.0 reload_config().
255 fi
256 return $OCF_SUCCESS
257 }
258
259 stop_rip_ipscip-shell shell shell-project 0.0.0 stop_rip_ip().() {
260 echoscip-shell system . . echo. stop_rip_ip
261 check_paramsscip-shell shell shell-project 0.0.0 check_params().
262 status_rip_ipscip-shell shell shell-project 0.0.0 status_rip_ip().
263 if [scip-shell system . . `[`. $? = $OCF_NOT_RUNNING ]
264 then
265 exit $OCF_SUCCESS
266 fi
267 $IP2UTIL addr del $OCF_RESKEY_ip dev lo
268 echoscip-shell system . . echo. sleep 2
269 sleepscip-shell system . . sleep. 2
270 del_ipscip-shell shell shell-project 0.0.0 del_ip(). $OCF_RESKEY_ip
271 return $OCF_SUCCESS
272 }
273
274 status_rip_ipscip-shell shell shell-project 0.0.0 status_rip_ip().() {
275 check_paramsscip-shell shell shell-project 0.0.0 check_params().
276 if $IP2UTIL addr | $GREP $OCF_RESKEY_ip >/dev/nullscip-shell filesystem . . `/dev/null`.
277 then
278 if $GREP $OCF_RESKEY_ip $RIPDCONF >/dev/nullscip-shell filesystem . . `/dev/null`.
279 then
280 if pidofscip-shell system . . pidof. ripd >/dev/nullscip-shell filesystem . . `/dev/null`.
281 then
282 return $OCF_SUCCESS
283 fi
284 fi
285 return $OCF_ERR_GENERIC
286 fi
287 return $OCF_NOT_RUNNING
288 }
289
290 if
291 [scip-shell system . . `[`. $# -ne 1 ]
292 then
293 usagescip-shell shell shell-project 0.0.0 usage().
294 exit $OCF_ERR_ARGS
295 fi
296
297 [scip-shell system . . `[`. x != x"$OCF_RESKEY_zebra_binary" ] &&
298 ZEBRA=$OCF_RESKEY_zebra_binary
299 [scip-shell system . . `[`. x != x"$OCF_RESKEY_ripd_binary" ] &&
300 RIPD=$OCF_RESKEY_ripd_binary
301
302 case $1 in
303 start) start_rip_ipscip-shell shell shell-project 0.0.0 start_rip_ip().;;
304 stop) stop_rip_ipscip-shell shell shell-project 0.0.0 stop_rip_ip().;;
305 status) status_rip_ipscip-shell shell shell-project 0.0.0 status_rip_ip().;;
306 monitor) status_rip_ipscip-shell shell shell-project 0.0.0 status_rip_ip().;;
307 validate-all) check_binary $IP2UTIL
308 exit $OCF_SUCCESS;;
309 meta-data) meta_datascip-shell shell shell-project 0.0.0 meta_data().;;
310 usage) usagescip-shell shell shell-project 0.0.0 usage().; exit $OCF_SUCCESS;;
311 *) usagescip-shell shell shell-project 0.0.0 usage().
312 exit $OCF_ERR_UNIMPLEMENTED
313 ;;
314 esac