OSDN Git Service

Update Heartbeat RA and cib.xml examples.
[ultramonkey-l7/ultramonkey-l7-v2.git] / doc / heartbeat-ra / L7vsd
1 #!/bin/sh
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of version 2 of the GNU General Public License as
5 # published by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it would be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 #
11 # Further, this software is distributed without any warranty that it is
12 # free of the rightful claim of any third person regarding infringement
13 # or the like.  Any license provided herein, whether implied or
14 # otherwise, applies only to this software file.  Patent licenses, if
15 # any, provided herein do not apply to combinations of this program with
16 # other software, or any other product whatsoever.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
21 #
22
23 #######################################################################
24 # Initialization:
25
26 . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
27 #. /usr/lib/ocf/resource.d/heartbeat/.ocf-shellfuncs
28
29 #######################################################################
30
31 meta_data() {
32         cat <<END
33 <?xml version="1.0"?>
34 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
35 <resource-agent name="L7vsd" version="1.0">
36 <version>1.0</version>
37
38 <longdesc lang="en">
39 This is a L7vsd Resource Agent.
40 </longdesc>
41 <shortdesc lang="en">L7vsd resource agent</shortdesc>
42
43 <parameter/>
44 <parameters/>
45
46 <actions>
47 <action name="start"        timeout="60" />
48 <action name="stop"         timeout="60" />
49 <action name="monitor"      timeout="60" interval="10" depth="0" start-delay="0" />
50 <action name="meta-data"    timeout="5" />
51 </actions>
52 </resource-agent>
53 END
54 }
55
56 #######################################################################
57
58 l7vsd_usage() {
59         cat <<END
60 usage: $0 {start|stop|monitor|meta-data}
61
62 END
63 }
64
65 ###############################
66 # Resource start Method
67 ###############################
68 l7vsd_start() {
69         ocf_log info "l7vsd is starting ..."
70         l7vsd_monitor
71         RET=$?
72         if [ $RET -eq $OCF_SUCCESS ]; then
73                 ocf_log info "l7vsd is already running."
74                 return $OCF_SUCCESS
75         elif [ $RET -eq $OCF_NOT_RUNNING ]; then
76                 /etc/init.d/l7vsd start > /dev/null 2>&1
77                 RET=$?
78                 if [ $RET -ne 0 ]; then
79                         MSG="l7vsd start error!"
80                         outputLog err ${OCF_ERR_GENERIC} $MSG
81                         return $OCF_ERR_GENERIC
82                 fi
83                 l7vsd_status
84                 if [ $? -eq $OCF_SUCCESS ]; then
85                         # l7vsd is running
86                         ocf_log info "l7vsd starts."
87                         return $OCF_SUCCSESS
88                 fi
89         fi
90         MSG="l7vsd does not work. (ps=$RET) "
91         outputLog err ${OCF_ERR_GENERIC} ${MSG}
92         return $OCF_ERR_GENERIC
93 }
94
95 ###############################
96 # Resource stop Method 
97 ###############################
98 l7vsd_stop() {
99         ocf_log info "l7vsd stopping ..."
100         isRunning;
101         RET=$?
102         if [ $RET -eq 0 ]; then
103                 ocf_log info "l7vsd stopped."
104                 return $OCF_SUCCESS
105         fi
106         /etc/init.d/l7vsd stop > /dev/null 2>&1
107         count=0
108         while [ $count -le 10 ]
109         do
110                 isRunning;
111                 RET=$?
112                 if [ $RET -eq 0 ]; then
113                         ocf_log info "l7vsd stopped."
114                         return $OCF_SUCCESS
115                 fi
116                 count=`expr $count + 1`
117                 sleep 1
118         done
119         l7vsd_pkill
120         RET=$?
121         return $RET
122 }
123
124 ###############################
125 # Logging Method
126 ###############################
127 outputLog(){
128         MODE=$1
129         shift
130         case $MODE in
131                 info)   RET=$1; shift;
132                         ocf_log $MODE "[$0 ${__OCF_ACTION}] OK;return=$RET" "$@";;
133                 err)    RET=$1; shift;
134                         ocf_log $MODE "[$0 ${__OCF_ACTION}] NG;return=$RET" "$@";;
135         esac
136 }
137
138 ###############################
139 # kill process
140 ###############################
141 l7vsd_pkill(){
142         pkill -9 -f "/usr/sbin/l7vsd"
143         ocf_log info "kill l7vsd process!"
144         while true
145         do
146                 sleep 1
147                 isRunning;
148                 RET=$?
149                 if [ $RET -eq 0 ]; then
150                      # stop OK
151                      ocf_log info "l7vsd process stopped!"
152                      return $OCF_SUCCESS
153                 fi
154         done
155 }
156
157 ###############################
158 # Resource Running Check Method
159 ###############################
160 isRunning(){
161         RET=0
162         RET=`ps -ef | grep /usr/sbin/l7vsd | grep -v grep | wc -l`
163         return $RET
164 }
165
166 ###############################
167 # Get Resource Status Method
168 ###############################
169 l7vsd_status(){
170         /etc/init.d/l7vsd status > /dev/null 2>&1
171         RET=$?
172         if [ $RET -eq 0 ]; then
173                 return $OCF_SUCCESS
174         else
175                 MSG="l7vsd status ERROR!: $RET"
176                 outputLog err ${OCF_ERR_GENERIC} ${MSG}
177                 return $OCF_ERR_GENERIC
178         fi
179 }
180
181 ###############################
182 # Get Resource Monitor Method
183 ###############################
184 l7vsd_monitor() {
185         isRunning;
186         RET=$?
187         if [ $RET -eq 1 ]; then
188                 # l7vsd is running
189                 l7vsd_status
190                 if [ $? -eq $OCF_SUCCESS ]; then
191                         # status OK
192                         return $OCF_SUCCESS
193                 else
194                         break
195                 fi
196         elif [ $RET -eq 0 ]; then
197                 MSG="l7vsd is not running."
198                 outputLog err ${OCF_NOT_RUNNING} ${MSG}
199                 return $OCF_NOT_RUNNING
200         fi
201         MSG="l7vsd does not work. (ps=$RET) "
202         outputLog err ${OCF_ERR_GENERIC} ${MSG}
203         return $OCF_ERR_GENERIC
204 }
205
206 case $__OCF_ACTION in
207 meta-data)      meta_data
208                 exit $OCF_SUCCESS ;;
209 start)          l7vsd_start;;
210 stop)           l7vsd_stop;;
211 monitor)        l7vsd_monitor;;
212 usage|help)     l7vsd_usage
213                 exit $OCF_SUCCESS
214                 ;;
215 *)              l7vsd_usage
216                 exit $OCF_ERR_UNIMPLEMENTED
217     
218                 ;;
219 esac
220 rc=$?
221 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
222 exit $rc