4
# Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved.
5
# Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
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.
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.
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.
24
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
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
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
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"
41
declare APACHE_parseConfig=$(dirname $0)/utils/httpd-parse-config.pl
43
apache_serverConfigFile()
45
if $(echo $OCF_RESKEY_config_file | grep -q "^/"); then
46
APACHE_serverConfigFile="$OCF_RESKEY_config_file"
48
APACHE_serverConfigFile="$OCF_RESKEY_server_root/$OCF_RESKEY_config_file"
56
clog_service_verify $CLOG_INIT
58
if [ -z "$OCF_RESKEY_name" ]; then
59
clog_service_verify $CLOG_FAILED "Invalid Name Of Service"
63
if [ -z "$OCF_RESKEY_service_name" ]; then
64
clog_service_verify $CLOG_FAILED_NOT_CHILD
68
if [ -z "$OCF_RESKEY_server_root" ]; then
69
clog_service_verify $CLOG_FAILED "Invalid ServerRoot"
73
if [ ! -d "$OCF_RESKEY_server_root" ]; then
74
clog_service_verify $CLOG_FAILED "ServerRoot Directory Is Missing"
78
if [ -z "$OCF_RESKEY_config_file" ]; then
79
clog_check_file_exist $CLOG_FAILED_INVALID "$OCF_RESKEY_config_file"
83
if [ ! -r "$APACHE_serverConfigFile" ]; then
84
clog_check_file_exist $CLOG_FAILED_NOT_READABLE "$APACHE_serverConfigFile"
88
if [ -z "$APACHE_pid_file" ]; then
89
clog_service_verify $CLOG_FAILED "Invalid name of PID file"
93
clog_check_syntax $CLOG_INIT "$APACHE_serverConfigFile"
96
-D"$OCF_RESKEY_name" \
97
-d "$OCF_RESKEY_server_root" \
98
-f "$APACHE_serverConfigFile" \
99
$OCF_RESKEY_httpd_options &> /dev/null
101
if [ $? -ne 0 ]; then
102
clog_check_syntax $CLOG_FAILED "$APACHE_serverConfigFile"
103
return $OCF_ERR_GENERIC
106
clog_check_syntax $CLOG_SUCCEED "$APACHE_serverConfigFile"
111
generate_configFile()
113
declare originalConfigFile=$1;
114
declare generatedConfigFile=$2;
115
declare ip_addresses=$3;
117
if [ -f "$generatedConfigFile" ]; then
118
sha1_verify "$generatedConfigFile"
119
if [ $? -ne 0 ]; then
120
clog_check_sha1 $CLOG_FAILED
125
clog_generate_config $CLOG_INIT "$originalConfigFile" "$generatedConfigFile"
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)
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}'`
145
for z in $ip_addresses; do
146
echo "Listen $z:$port" >> "$generatedConfigFile";
152
echo "PidFile \"$APACHE_pid_file\"" >> "$generatedConfigFile";
153
echo >> "$generatedConfigFile"
155
cat "$originalConfigFile" | sed 's/^Listen/### Listen/;s/^Port/### Port/;s/^PidFile/### PidFile/' | \
156
"$APACHE_parseConfig" -D"$OCF_RESKEY_name" >> "$generatedConfigFile"
158
sha1_addToFile "$generatedConfigFile"
159
clog_generate_config $CLOG_SUCCEED "$originalConfigFile" "$generatedConfigFile"
166
clog_service_start $CLOG_INIT
169
create_conf_directory "$APACHE_conf_dir"
170
check_pid_file "$APACHE_pid_file"
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
178
clog_looking_for $CLOG_INIT "IP Addresses"
180
get_service_ip_keys "$OCF_RESKEY_service_name"
181
ip_addresses=`build_ip_list`
183
if [ -z "$ip_addresses" ]; then
184
clog_looking_for $CLOG_FAILED_NOT_FOUND "IP Addresses"
185
return $OCF_ERR_GENERIC
188
clog_looking_for $CLOG_SUCCEED "IP Addresses"
190
generate_configFile "$APACHE_serverConfigFile" "$APACHE_genConfig" "$ip_addresses"
193
"-D$OCF_RESKEY_name" \
194
-d "$OCF_RESKEY_server_root" \
195
-f "$APACHE_genConfig" \
196
$OCF_RESKEY_httpd_options \
199
if [ $? -ne 0 ]; then
200
clog_service_start $CLOG_FAILED
201
return $OCF_ERR_GENERIC
203
clog_service_start $CLOG_SUCCEED
211
clog_service_stop $CLOG_INIT
213
stop_generic "$APACHE_pid_file" "$OCF_RESKEY_shutdown_wait"
215
if [ $? -ne 0 ]; then
216
clog_service_stop $CLOG_FAILED
217
return $OCF_ERR_GENERIC
220
clog_service_stop $CLOG_SUCCEED
226
clog_service_status $CLOG_INIT
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
234
clog_service_status $CLOG_SUCCEED
238
if [ "$1" != "meta-data" ]; then
239
apache_serverConfigFile
244
cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
247
validate-all|verify-all)
271
echo "Usage: $0 {start|stop|status|monitor|restart|meta-data|validate-all}"
272
exit $OCF_ERR_UNIMPLEMENTED