OSDN Git Service

UltraMonkey-L7 2.1.3-1 release.
[ultramonkey-l7/ultramonkey-l7-v2.git] / doc / heartbeat-ra / SSLProxy
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="SSLProxy" version="1.0">
36 <version>1.0</version>
37
38 <longdesc lang="en">
39 This is a SSLProxy Resource Agent.
40 </longdesc>
41 <shortdesc lang="en">SSLProxy resource agent</shortdesc>
42
43 <parameters>
44 <parameter name="state" unique="1">
45 <longdesc lang="en">
46 Location to store the resource state in.
47 </longdesc>
48 <shortdesc lang="en">State file</shortdesc>
49 <content type="string" default="" />
50 </parameter>
51
52 </parameters>
53
54 <actions>
55 <action name="start"        timeout="60" />
56 <action name="stop"         timeout="60" />
57 <action name="monitor"      timeout="60" interval="10" depth="0" start-delay="0" />
58 <action name="meta-data"    timeout="5" />
59 </actions>
60 </resource-agent>
61 END
62 }
63
64 #######################################################################
65
66 sslproxy_usage() {
67         cat <<END
68 usage: $0 {start|stop|monitor|meta-data}
69 END
70 }
71
72 ###############################
73 # Logging Method
74 ###############################
75 outputLog(){
76         MODE=$1
77         shift
78         case $MODE in
79                 err)    RET=$1; shift;
80                         ocf_log $MODE "[$0 ${__OCF_ACTION}] NG;return=$RET" "$@";;
81         esac
82 }
83
84 ###############################
85 # kill process
86 ###############################
87 sslproxy_pkill(){
88         pkill -9 sslproxy
89         ocf_log info "kill sslproxy process!"
90         while true
91         do
92                 sleep 1
93                 isRunning
94                 RET=$?
95                 if [ $RET -eq 0 ]; then
96                         # stop OK
97                         ocf_log info "sslproxy process stopped!"
98                         return ${OCF_SUCCESS}
99                 fi
100         done 
101 }
102
103 ###############################
104 # Resource Running Check Method
105 ###############################
106 isRunning(){
107         RET=0
108         RET=`pgrep -fox '/usr/sbin/sslproxy .*' | wc -l`
109         return $RET
110 }
111
112 ###############################
113 # Get Resource Status Method
114 ###############################
115 sslproxy_status(){
116         T_ID=`/usr/sbin/sslproxyadm status | grep "TargetID" | wc -l`
117         RET=`/usr/sbin/sslproxyadm status | grep "Starting. PID =" | wc -l`
118         if [ $RET -eq 0 ]; then
119                 MSG="sslproxy status ERROR!."
120                 outputLog err ${OCF_ERR_GENERIC} ${MSG}
121                 return ${OCF_ERR_GENERIC}
122         elif [ $RET -lt $T_ID ]; then
123                 MSG="sslproxy status ERROR!(Target is insufficient)."
124                 outputLog err ${OCF_ERR_GENERIC} ${MSG}
125                 return ${OCF_ERR_GENERIC}
126 #       elif [ $RET -gt $T_ID ]; then
127 #               MSG="sslproxy status ERROR!(Target_ID exceeds a set value)."
128 #               outputLog err ${OCF_ERR_GENERIC} ${MSG}
129 #               return ${OCF_ERR_GENERIC}
130         fi
131         return ${OCF_SUCCESS}
132 }
133
134 ###############################
135 # Get Resource Monitor Method
136 ###############################
137 sslproxy_monitor() {
138         isRunning;
139         RET=$?
140         if [ $RET -eq 0 ]; then
141                 MSG="sslproxy is not running."  
142                 outputLog err ${OCF_NOT_RUNNING} ${MSG}
143                 return ${OCF_NOT_RUNNING}
144         else
145                 # sslproxy is running
146                 sslproxy_status
147                 if [ $? -eq ${OCF_SUCCESS} ]; then
148                         # status OK
149                         return ${OCF_SUCCESS}
150                 else
151                         break
152                 fi              
153         fi
154         MSG="sslproxy does not work."
155         outputLog err ${OCF_ERR_GENERIC} ${MSG}
156         return ${OCF_ERR_GENERIC}
157 }
158
159 ###############################
160 # Resource start Method
161 ###############################
162 sslproxy_start() {
163         ocf_log info "sslproxy is starting ..."
164         sslproxy_monitor
165         RET=$?
166         if [ $RET -eq ${OCF_SUCCESS} ]; then
167                 ocf_log info "sslproxy is already running."
168                 return $OCF_SUCCESS
169         fi
170         /usr/sbin/sslproxyadm start > /dev/null 2>&1
171         RET=$?
172         if [ $RET -ne 0 ];then
173                 MSG="sslproxy start error!."
174                 outputLog err ${OCF_ERR_GENERIC} $MSG
175                 return ${OCF_ERR_GENERIC}
176         fi
177         while true
178         do
179                 isRunning;
180                 RET=$?
181                 if [ $RET -ne 0 ]; then
182                         # sslproxy is running
183                         ocf_log info "sslproxy starts."
184                         return ${OCF_SUCCESS}
185                 fi
186                 sleep 1
187         done
188 }
189
190 ###############################
191 # Resource stop Method
192 ###############################
193 sslproxy_stop() {
194         ocf_log info "sslproxy is stopping ..."
195         isRunning;
196         RET=$?
197         if [ $RET -eq 0 ]; then
198                 ocf_log info "sslproxy stopped."
199                 return ${OCF_SUCCESS}
200         fi
201         /usr/sbin/sslproxyadm stop > /dev/null 2>&1
202         count=0
203         while [ $count -le 10 ]
204         do
205                 isRunning;
206                 RET=$?
207                 if [ $RET -eq 0 ]; then
208                         ocf_log info "sslproxy stopped."
209                         return ${OCF_SUCCESS}
210                 fi
211                 $count=`expr $count + 1`
212                 sleep 1
213         done
214         
215         sslproxy_pkill
216         RET=$?  
217         
218         return $RET
219 }
220
221 case $__OCF_ACTION in
222 meta-data)      meta_data
223                 exit $OCF_SUCCESS ;;
224 start)          sslproxy_start ;;
225 stop)           sslproxy_stop ;;
226 monitor)        sslproxy_monitor ;;
227 usage|help)     sslproxy_usage
228                 exit $OCF_SUCCESS
229                 ;;
230 *)              sslproxy_usage
231                 exit $OCF_ERR_UNIMPLEMENTED
232                 ;;
233 esac
234 rc=$?
235 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
236 exit $rc