OSDN Git Service

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