~ubuntu-branches/debian/stretch/resource-agents/stretch

« back to all changes in this revision

Viewing changes to rgmanager/src/resources/apache.sh

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
ImportĀ upstreamĀ versionĀ 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
#
 
4
# Copyright (C) 1997-2003 Sistina Software, Inc.  All rights reserved.
 
5
# Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
 
6
#
 
7
# This program is free software; you can redistribute it and/or
 
8
# modify it under the terms of the GNU General Public License
 
9
# as published by the Free Software Foundation; either version 2
 
10
# of the License, or (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with this program; if not, write to the Free Software
 
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
#
 
21
 
 
22
export LC_ALL=C
 
23
export LANG=C
 
24
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 
25
 
 
26
. $(dirname $0)/ocf-shellfuncs
 
27
. $(dirname $0)/utils/config-utils.sh
 
28
. $(dirname $0)/utils/messages.sh
 
29
. $(dirname $0)/utils/ra-skelet.sh
 
30
 
 
31
if [ -x /usr/sbin/httpd ]; then
 
32
        declare APACHE_HTTPD=/usr/sbin/httpd
 
33
elif [ -x /usr/sbin/apache2 ]; then
 
34
        declare APACHE_HTTPD=/usr/sbin/apache2
 
35
fi
 
36
declare APACHE_serverConfigFile
 
37
declare APACHE_pid_file="`generate_name_for_pid_file`"
 
38
declare APACHE_conf_dir="`generate_name_for_conf_dir`"
 
39
declare APACHE_genConfig="$APACHE_conf_dir/httpd.conf"
 
40
 
 
41
declare APACHE_parseConfig=$(dirname $0)/utils/httpd-parse-config.pl
 
42
 
 
43
apache_serverConfigFile()
 
44
{
 
45
        if $(echo $OCF_RESKEY_config_file | grep -q "^/"); then
 
46
                APACHE_serverConfigFile="$OCF_RESKEY_config_file"
 
47
        else 
 
48
                APACHE_serverConfigFile="$OCF_RESKEY_server_root/$OCF_RESKEY_config_file"
 
49
        fi
 
50
 
 
51
        return;
 
52
}
 
53
 
 
54
verify_all()
 
55
{
 
56
        clog_service_verify $CLOG_INIT 
 
57
 
 
58
        if [ -z "$OCF_RESKEY_name" ]; then
 
59
                clog_service_verify $CLOG_FAILED "Invalid Name Of Service"
 
60
                return $OCF_ERR_ARGS
 
61
        fi
 
62
 
 
63
        if [ -z "$OCF_RESKEY_service_name" ]; then
 
64
                clog_service_verify $CLOG_FAILED_NOT_CHILD
 
65
                return $OCF_ERR_ARGS
 
66
        fi
 
67
                                                        
 
68
        if [ -z "$OCF_RESKEY_server_root" ]; then
 
69
                clog_service_verify $CLOG_FAILED "Invalid ServerRoot"
 
70
                return $OCF_ERR_ARGS
 
71
        fi
 
72
 
 
73
        if [ ! -d "$OCF_RESKEY_server_root" ]; then
 
74
                clog_service_verify $CLOG_FAILED "ServerRoot Directory Is Missing"
 
75
                return $OCF_ERR_ARGS
 
76
        fi
 
77
 
 
78
        if [ -z "$OCF_RESKEY_config_file" ]; then
 
79
                clog_check_file_exist $CLOG_FAILED_INVALID "$OCF_RESKEY_config_file"
 
80
                return $OCF_ERR_ARGS
 
81
        fi
 
82
 
 
83
        if [ ! -r "$APACHE_serverConfigFile" ]; then
 
84
                clog_check_file_exist $CLOG_FAILED_NOT_READABLE "$APACHE_serverConfigFile"
 
85
                return $OCF_ERR_ARGS
 
86
        fi
 
87
 
 
88
        if [ -z "$APACHE_pid_file" ]; then
 
89
                clog_service_verify $CLOG_FAILED "Invalid name of PID file"
 
90
                return $OCF_ERR_ARGS
 
91
        fi
 
92
 
 
93
        clog_check_syntax $CLOG_INIT "$APACHE_serverConfigFile"
 
94
 
 
95
        "$APACHE_HTTPD" -t \
 
96
                -D"$OCF_RESKEY_name" \
 
97
                -d "$OCF_RESKEY_server_root" \
 
98
                -f "$APACHE_serverConfigFile" \
 
99
                $OCF_RESKEY_httpd_options &> /dev/null
 
100
                
 
101
        if [ $? -ne 0 ]; then
 
102
                clog_check_syntax $CLOG_FAILED "$APACHE_serverConfigFile"
 
103
                return $OCF_ERR_GENERIC
 
104
        fi
 
105
 
 
106
        clog_check_syntax $CLOG_SUCCEED "$APACHE_serverConfigFile"
 
107
 
 
108
        return 0
 
109
}
 
110
 
 
111
generate_configFile()
 
112
{
 
113
        declare originalConfigFile=$1;
 
114
        declare generatedConfigFile=$2;
 
115
        declare ip_addresses=$3;
 
116
 
 
117
        if [ -f "$generatedConfigFile" ]; then
 
118
                sha1_verify "$generatedConfigFile"
 
119
                if [ $? -ne 0 ]; then
 
120
                        clog_check_sha1 $CLOG_FAILED
 
121
                        return 0
 
122
                fi
 
123
        fi      
 
124
 
 
125
        clog_generate_config $CLOG_INIT "$originalConfigFile" "$generatedConfigFile"
 
126
 
 
127
        generate_configTemplate "$generatedConfigFile" "$1"
 
128
        cat >> "$generatedConfigFile" << EOT
 
129
# From a cluster perspective, the key fields are:
 
130
#     Listen - must be set to service floating IP address.
 
131
#     ServerRoot - path to the ServerRoot (initial value is set in service conf)
 
132
#
 
133
 
 
134
EOT
 
135
 
 
136
        IFS_old="$IFS"
 
137
        IFS=$'\n'
 
138
        for i in `"$APACHE_parseConfig" -D"$OCF_RESKEY_name" < "$originalConfigFile" | grep -P '(^Listen)|(^Port)' `; do 
 
139
                port=`echo $i | sed 's/^Listen \(.*\)/\1/;s/^Port \(.*\)/\1/'`;
 
140
                testcond=`echo $port|grep :`
 
141
                if [ $testcond ]; then
 
142
                        port=`echo $port|awk -F : '{print $2}'`
 
143
                fi
 
144
                IFS=$' ';
 
145
                for z in $ip_addresses; do 
 
146
                        echo "Listen $z:$port" >> "$generatedConfigFile";
 
147
                done
 
148
                IFS=$'\n';
 
149
        done;
 
150
        IFS="$IFS_old"
 
151
 
 
152
        echo "PidFile \"$APACHE_pid_file\"" >> "$generatedConfigFile";
 
153
        echo >> "$generatedConfigFile"
 
154
 
 
155
        cat "$originalConfigFile" | sed 's/^Listen/### Listen/;s/^Port/### Port/;s/^PidFile/### PidFile/' | \
 
156
        "$APACHE_parseConfig" -D"$OCF_RESKEY_name" >> "$generatedConfigFile"
 
157
 
 
158
        sha1_addToFile "$generatedConfigFile"
 
159
        clog_generate_config $CLOG_SUCCEED "$originalConfigFile" "$generatedConfigFile"
 
160
}
 
161
 
 
162
start()
 
163
{
 
164
        declare ip_addresses
 
165
 
 
166
        clog_service_start $CLOG_INIT   
 
167
 
 
168
        create_pid_directory
 
169
        create_conf_directory "$APACHE_conf_dir"
 
170
        check_pid_file "$APACHE_pid_file"
 
171
 
 
172
        if [ $? -ne 0 ]; then
 
173
                clog_check_pid $CLOG_FAILED "$APACHE_pid_file"
 
174
                clog_service_start $CLOG_FAILED
 
175
                return $OCF_ERR_GENERIC
 
176
        fi
 
177
 
 
178
        clog_looking_for $CLOG_INIT "IP Addresses"
 
179
 
 
180
        get_service_ip_keys "$OCF_RESKEY_service_name"
 
181
        ip_addresses=`build_ip_list`
 
182
 
 
183
        if [ -z "$ip_addresses" ]; then
 
184
                clog_looking_for $CLOG_FAILED_NOT_FOUND "IP Addresses"
 
185
                return $OCF_ERR_GENERIC
 
186
        fi
 
187
        
 
188
        clog_looking_for $CLOG_SUCCEED "IP Addresses"
 
189
 
 
190
        generate_configFile "$APACHE_serverConfigFile" "$APACHE_genConfig" "$ip_addresses"
 
191
 
 
192
        "$APACHE_HTTPD" \
 
193
                "-D$OCF_RESKEY_name" \
 
194
                -d "$OCF_RESKEY_server_root" \
 
195
                -f "$APACHE_genConfig" \
 
196
                $OCF_RESKEY_httpd_options \
 
197
                -k start
 
198
 
 
199
        if [ $? -ne 0 ]; then
 
200
                clog_service_start $CLOG_FAILED         
 
201
                return $OCF_ERR_GENERIC
 
202
        else
 
203
                clog_service_start $CLOG_SUCCEED
 
204
        fi
 
205
 
 
206
        return 0;
 
207
}
 
208
 
 
209
stop()
 
210
{
 
211
        clog_service_stop $CLOG_INIT
 
212
 
 
213
        stop_generic "$APACHE_pid_file" "$OCF_RESKEY_shutdown_wait"
 
214
        
 
215
        if [ $? -ne 0 ]; then
 
216
                clog_service_stop $CLOG_FAILED
 
217
                return $OCF_ERR_GENERIC
 
218
        fi
 
219
        
 
220
        clog_service_stop $CLOG_SUCCEED
 
221
        return 0;
 
222
}
 
223
 
 
224
status()
 
225
{
 
226
        clog_service_status $CLOG_INIT
 
227
 
 
228
        status_check_pid "$APACHE_pid_file"
 
229
        if [ $? -ne 0 ]; then
 
230
                clog_service_status $CLOG_FAILED "$APACHE_pid_file"
 
231
                return $OCF_ERR_GENERIC
 
232
        fi
 
233
 
 
234
        clog_service_status $CLOG_SUCCEED
 
235
        return 0
 
236
}
 
237
 
 
238
if [ "$1" != "meta-data" ]; then
 
239
        apache_serverConfigFile
 
240
fi;
 
241
                
 
242
case $1 in
 
243
        meta-data)
 
244
                cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
 
245
                exit 0
 
246
                ;;
 
247
        validate-all|verify-all)
 
248
                verify_all
 
249
                exit $?
 
250
                ;;
 
251
        start)
 
252
                verify_all && start
 
253
                exit $?
 
254
                ;;
 
255
        stop)
 
256
                verify_all && stop
 
257
                exit $?
 
258
                ;;
 
259
        status|monitor)
 
260
                verify_all
 
261
                status
 
262
                exit $?
 
263
                ;;
 
264
        restart)
 
265
                verify_all
 
266
                stop
 
267
                start
 
268
                exit $?
 
269
                ;;
 
270
        *)
 
271
                echo "Usage: $0 {start|stop|status|monitor|restart|meta-data|validate-all}"
 
272
                exit $OCF_ERR_UNIMPLEMENTED
 
273
                ;;
 
274
esac