OSDN Git Service

Merged DHC codes
[ultramonkey-l7/ultramonkey-l7-v3.git] / doc / heartbeat-ra / VIPcheck
1 #!/bin/sh
2 #
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of version 2 of the GNU General Public License as
6 # published by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it would be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 #
12 # Further, this software is distributed without any warranty that it is
13 # free of the rightful claim of any third person regarding infringement
14 # or the like.  Any license provided herein, whether implied or
15 # otherwise, applies only to this software file.  Patent licenses, if
16 # any, provided herein do not apply to combinations of this program with
17 # other software, or any other product whatsoever.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 #
23
24 #######################################################################
25 # Initialization:
26
27 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
28 #. /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
29
30 #######################################################################
31
32 meta_data() {
33         cat <<END
34 <?xml version="1.0"?>
35 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
36 <resource-agent name="VIPcheck" version="0.1">
37 <version>1.0</version>
38
39 <longdesc lang="en">
40 This is a VIPcheck Resource Agent.
41 </longdesc>
42 <shortdesc lang="en">VIPcheck resource agent</shortdesc>
43
44 <parameters>
45 <parameter name="target_ip" unique="1">
46 <longdesc lang="en">
47 ping target VIP address.
48 </longdesc>
49 <shortdesc lang="en">target ip</shortdesc>
50 <content type="string" default="" />
51 </parameter>
52
53 <parameter name="count" unique="1">
54 <longdesc lang="en">
55 repeat times
56 </longdesc>
57 <shortdesc lang="en">repeat times</shortdesc>
58 <content type="integer" default="1" />
59 </parameter>
60
61 <parameter name="wait" unique="1">
62 <longdesc lang="en">
63 wait times
64 </longdesc>
65 <shortdesc lang="en">wait times</shortdesc>
66 <content type="integer" default="10" />
67 </parameter>
68
69 </parameters>
70
71 <actions>
72 <action name="start"        timeout="60" />
73 <action name="stop"         timeout="60" />
74 <action name="monitor"      timeout="60" interval="10" depth="0" start-delay="0" />
75 <action name="meta-data"    timeout="5" />
76 </actions>
77 </resource-agent>
78 END
79 }
80
81 #######################################################################
82
83 VIPcheck_usage() {
84         cat <<END
85 usage: $0 {start|stop|monitor|meta-data}
86
87 Expects to have a fully populated OCF RA-compliant environment set.
88 END
89 }
90
91 VIPcheck_start() {
92         VIPcheck_monitor
93         if [ $? =  $OCF_SUCCESS ]; then
94                 return $OCF_SUCCESS
95         fi 
96
97         ping ${OCF_RESKEY_target_ip} -c ${OCF_RESKEY_count} -w ${OCF_RESKEY_wait} > /dev/null 2>&1
98         prc=$?
99         ocf_log debug "target_ip = $OCF_RESKEY_target_ip, count = $OCF_RESKEY_count, wait = $OCF_RESKEY_wait"
100         ocf_log debug "ping return code = $prc"
101         if [ $prc = 0 ]; then 
102                 # pingが通った-->ERROR
103                 return $OCF_ERR_GENERIC
104         else 
105                 # pingが通らない --> 成功
106                 touch ${OCF_RESKEY_state}
107                 return $OCF_SUCCESS
108         fi
109 }
110
111 VIPcheck_stop() {
112         VIPcheck_monitor
113         if [ $? =  $OCF_SUCCESS ]; then
114                 rm ${OCF_RESKEY_state}
115         fi
116         return $OCF_SUCCESS
117 }
118
119 VIPcheck_monitor() {
120         if [ -f ${OCF_RESKEY_state} ]; then
121                 return $OCF_SUCCESS
122         fi
123         if false ; then
124                 return $OCF_ERR_GENERIC
125         fi
126         return $OCF_NOT_RUNNING
127 }
128
129 : ${OCF_RESKEY_wait=10}
130 : ${OCF_RESKEY_count=1}
131 : ${OCF_RESKEY_state=${HA_RSCTMP}/VIPcheck-${OCF_RESOURCE_INSTANCE}.state}
132
133 case $__OCF_ACTION in
134 meta-data)      meta_data
135                 exit $OCF_SUCCESS
136                 ;;
137 start)          VIPcheck_start;;
138 stop)           VIPcheck_stop;;
139 monitor)        VIPcheck_monitor;;
140 usage|help)     VIPcheck_usage
141                 exit $OCF_SUCCESS
142                 ;;
143 *)              VIPcheck_usage
144                 exit $OCF_ERR_UNIMPLEMENTED
145                 ;;
146 esac
147 rc=$?
148 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
149 exit $rc
150