[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/rgmanager/src/resources apache.sh apac ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	mgrac sourceware org	2006-08-31 15:01:10

Added files:
	rgmanager/src/resources: apache.sh apache.metadata 
	rgmanager/src/resources/utils: httpd-parse-config.pl 

Log message:
	Bug #204057. Adding Apache resource agent and utility which parse httpd.conf.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/apache.sh.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/apache.metadata.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/rgmanager/src/resources/utils/httpd-parse-config.pl.diff?cvsroot=cluster&r1=NONE&r2=1.1

/cvs/cluster/cluster/rgmanager/src/resources/apache.sh,v  -->  standard output
revision 1.1
--- cluster/rgmanager/src/resources/apache.sh
+++ -	2006-08-31 15:01:10.821747000 +0000
@@ -0,0 +1,313 @@
+#!/bin/bash
+
+#
+#  Copyright Red Hat, Inc. 2006
+#
+#  This program is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU General Public License as published by the
+#  Free Software Foundation; either version 2, or (at your option) any
+#  later version.
+#
+#  This program is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; see the file COPYING.  If not, write to the
+#  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
+#  MA 02139, USA.
+#
+#
+#  Author(s):
+#	Marek Grac (mgrac at redhat.com)
+#
+
+export LC_ALL=C
+export LANG=C
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+
+declare APACHE_HTTPD=/usr/sbin/httpd
+declare APACHE_genConfig="/tmp/httpd.$OCF_RESKEY_name"
+declare APACHE_pidFile
+declare APACHE_serverConfigFile
+declare APACHE_defaultPidFile=run/httpd.pid
+
+. $(dirname $0)/ocf-shellfuncs
+. $(dirname $0)/utils/config-utils.sh
+. $(dirname $0)/utils/messages.sh
+
+declare APACHE_parseConfig=$(dirname $0)/utils/httpd-parse-config.pl
+
+apache_pidFile()
+{
+	declare tmpFile="/tmp/httpd.$OCF_RESKEY_name.$$"
+	declare CFG_pidFile
+	declare CFG_serverRoot
+
+	if [ -f "$APACHE_genConfig" ]; then
+		sha1_verify "$APACHE_genConfig"
+		if [ $? -ne 0 ]; then
+			ocf_log debug "Config file changed; skipping"
+			cp "$APACHE_genConfig" "$tmpFile"
+		else 
+			generate_configFile "$APACHE_serverConfigFile" "$tmpFile"
+		fi
+	else
+		generate_configFile "$APACHE_serverConfigFile" "$tmpFile"
+	fi	
+
+	CFG_pidFile=`grep -e '^PidFile' "$tmpFile" | head -n 1 | \
+		sed 's/^PidFile "\(.*\)"/\1/;s/^PidFile \(.*\)/\1/'`
+	CFG_serverRoot=`grep -e '^ServerRoot' "$tmpFile" | head -n 1 | \
+		sed 's/^ServerRoot "\(.*\)"/\1/;s/^ServerRoot \(.*\)/\1/'`
+
+	if [ -z "$CFG_pidFile" ]; then
+		CFG_pidFile="$APACHE_defaultPidFile"
+	fi
+
+	if [ -z "$CFG_serverRoot" ]; then
+		CFG_serverRoot="$OCF_RESKEY_serverRoot"
+	fi
+
+	if [[ "$CFG_pidFile" =~ '^/' ]]; then
+		APACHE_pidFile="$CFG_pidFile"
+	else 
+		APACHE_pidFile="$CFG_serverRoot/$CFG_pidFile"
+	fi
+
+	rm -f "$tmpFile"
+
+	return;
+}
+
+apache_serverConfigFile()
+{
+	if [[ "$OCF_RESKEY_serverConfigFile" =~ '^/' ]]; then
+		APACHE_serverConfigFile="$OCF_RESKEY_serverConfigFile"
+	else 
+		APACHE_serverConfigFile="$OCF_RESKEY_serverRoot/$OCF_RESKEY_serverConfigFile"
+	fi
+
+	return;
+}
+
+verify_all()
+{
+	clog_service_verify $CLOG_INIT 
+	
+	if [ -z "$OCF_RESKEY_serverRoot" ]; then
+		clog_service_verify $CLOG_FAILED "Invalid ServerRoot"
+		return $OCF_ERR_ARGS
+	fi
+
+	if [ ! -d "$OCF_RESKEY_serverRoot" ]; then
+		clog_service_verify $CLOG_FAILED "ServerRoot Directory Is Missing"
+		return $OCF_ERR_ARGS
+	fi
+
+	if [ -z "$OCF_RESKEY_serverConfigFile" ]; then
+		clog_check_file_exist $CLOG_FAILED_INVALID "$OCF_RESKEY_serverConfigFile"
+		return $OCF_ERR_ARGS
+	fi
+
+	if [ ! -r "$APACHE_serverConfigFile" ]; then
+		clog_check_file_exist $CLOG_FAILED_NOT_READABLE "$APACHE_serverConfigFile"
+		return $OCF_ERR_ARGS
+	fi
+
+	if [ -z "$APACHE_pidFile" ]; then
+		clog_service_verify $CLOG_FAILED "Invalid name of PID file"
+		return $OCF_ERR_ARGS
+	fi
+
+	clog_check_syntax $CLOG_INIT "$APACHE_serverConfigFile"
+
+	"$APACHE_HTTPD" -t \
+		-D"$OCF_RESKEY_name" \
+		-d "$OCF_RESKEY_serverRoot" \
+		-f "$APACHE_serverConfigFile" &> /dev/null
+		
+	if [ $? -ne 0 ]; then
+		clog_check_syntax $CLOG_FAILED "$APACHE_serverConfigFile"
+		return $OCF_ERR_GENERIC
+	fi
+
+	clog_check_syntax $CLOG_SUCCEED "$APACHE_serverConfigFile"
+
+	return 0
+}
+
+generate_configFile()
+{
+	declare originalConfigFile=$1;
+	declare generatedConfigFile=$2;
+	declare ip_addresses=$3;
+
+	if [ -f "$generatedConfigFile" ]; then
+		sha1_verify "$generatedConfigFile"
+		if [ $? -ne 0 ]; then
+			clog_check_sha1 $CLOG_FAILED
+			return 0
+		fi
+	fi	
+
+	clog_generate_config $CLOG_INIT "$originalConfigFile" "$generatedConfigFile"
+
+	generate_configTemplate "$generatedConfigFile" "$1"
+	cat >> "$generatedConfigFile" << EOT
+# From a cluster perspective, the key fields are:
+#     Listen - must be set to service floating IP address.
+#     PidFile - path to the file where PID of running application is stored
+#     ServerRoot - path to the ServerRoot (initial value is set in service conf)
+#
+
+EOT
+
+	IFS_old="$IFS"
+	IFS=$'\n'
+	for i in `"$APACHE_parseConfig" -D"$OCF_RESKEY_name" < "$originalConfigFile" | grep -P '(^Listen)|(^Port)' | grep -v ':'`; do 
+		port=`echo $i | sed 's/^Listen \(.*\)/\1/;s/^Port \(.*\)/\1/'`;
+		IFS=$' ';
+		for z in $ip_addresses; do 
+			echo "Listen $z:$port" >> "$generatedConfigFile";
+		done
+		IFS=$'\n';
+	done;
+	IFS="$IFS_old"
+
+	cat "$originalConfigFile" | sed 's/^Listen/### Listen/;s/^Port/### Port/' | \
+	"$APACHE_parseConfig" -D"$OCF_RESKEY_name" >> "$generatedConfigFile"
+
+	sha1_addToFile "$generatedConfigFile"
+	clog_generate_config $CLOG_SUCCEED "$originalConfigFile" "$generatedConfigFile"
+}
+
+start()
+{
+	declare ccs_fd
+	declare ip_addresses
+
+	clog_service_start $CLOG_INIT	
+
+	if [ -e "$APACHE_pidFile" ]; then
+		clog_check_pid $CLOG_FAILED "$APACHE_pidFile"
+		clog_service_start $CLOG_FAILED
+		return $OCF_GENERIC_ERROR
+	fi
+
+	clog_looking_for $CLOG_INIT "IP Addresses"
+
+	ccs_fd=$(ccs_connect);
+	if [ $? -ne 0 ]; then
+		clog_looking_for $CLOG_FAILED_CCS
+		return $OCF_GENERIC_ERROR
+	fi
+	
+	get_service_ip_keys "$ccs_fd" "$OCF_RESKEY_service_name"
+	ip_addresses=`build_ip_list "$ccs_fd"`
+
+	if [ -z "$ip_addresses" ]; then
+		clog_looking_for $CLOG_FAILED_NOT_FOUND "IP Addresses"
+		return $OCF_GENERIC_ERROR
+	fi
+	
+	clog_looking_for $CLOG_SUCCEED "IP Addresses"
+
+	generate_configFile "$APACHE_serverConfigFile" "$APACHE_genConfig" "$ip_addresses"
+
+	"$APACHE_HTTPD" \
+		"-D$OCF_RESKEY_name" \
+		-d "$OCF_RESKEY_serverRoot" \
+		-f "$APACHE_genConfig" \
+		-k start
+
+	if [ $? -ne 0 ]; then
+		clog_service_start $CLOG_FAILED		
+		return $OCF_ERR_GENERIC
+	else
+		clog_service_start $CLOG_SUCCEED
+	fi
+
+	return 0;
+}
+
+stop()
+{
+	clog_service_stop $CLOG_INIT
+
+	if [ ! -e "$APACHE_pidFile" ]; then
+		clog_check_file_exist $CLOG_FAILED_NOT_FOUND "$APACHE_pidFile"
+		clog_service_stop $CLOG_FAILED
+		return $OCF_GENERIC_ERROR
+	fi
+
+	"$APACHE_HTTPD" -k stop
+
+	if [ $? -ne 0 ]; then
+		clog_service_stop $CLOG_FAILED
+		return $OCF_GENERIC_ERROR
+	else
+		clog_service_stop $CLOG_SUCCEED
+	fi
+	
+	return 0;
+}
+
+status()
+{
+	clog_service_status $CLOG_INIT
+
+	if [ ! -e "$APACHE_pidFile" ]; then
+		clog_check_file_exist $CLOG_FAILED "$APACHE_pidFile"
+		clog_service_status $CLOG_FAILED
+		return $OCF_GENERIC_ERROR
+	fi
+
+	if [ ! -d /proc/`cat "$APACHE_pidFile"` ]; then
+		clog_service_status $CLOG_FAILED
+		return $OCF_GENERIC_ERROR
+	fi	
+
+	clog_service_status $CLOG_SUCCEED
+	return 0
+}
+
+if [ "$1" != "meta-data" ]; then
+	apache_serverConfigFile
+	apache_pidFile
+fi;
+		
+case $1 in
+	meta-data)
+		cat $(dirname $0)/apache.metadata
+		exit 0
+		;;
+	verify-all)
+		verify_all
+		exit $?
+		;;
+	start)
+		verify_all && start
+		exit $?
+		;;
+	stop)
+		verify_all && stop
+		exit $?
+		;;
+	status|monitor)
+		verify_all
+		status
+		exit $?
+		;;
+	restart)
+		verify_all
+		stop
+		start
+		exit $?
+		;;
+	*)
+		echo "Usage: $0 {start|stop|status|monitor|restart|meta-data|verify-all}"
+		exit $OCF_ERR_GENERIC
+		;;
+esac
/cvs/cluster/cluster/rgmanager/src/resources/apache.metadata,v  -->  standard output
revision 1.1
--- cluster/rgmanager/src/resources/apache.metadata
+++ -	2006-08-31 15:01:10.905133000 +0000
@@ -0,0 +1,75 @@
+<?xml version="1.0"?>
+<resource-agent version="rgmanager 2.0" name="apache">
+    <version>1.0</version>
+
+    <longdesc lang="en">
+        This defines an instance of Apache web server
+    </longdesc>
+    <shortdesc lang="en">
+        Defines an Apache web server
+    </shortdesc>
+
+    <parameters>
+        <parameter name="name" primary="1">
+	    <longdesc lang="en">
+	        Define a name for use in &lt;IfDefine name&gt; directive.
+	    </longdesc>
+            <shortdesc lang="en">
+                Name
+            </shortdesc>
+	    <content type="string"/>
+        </parameter>
+
+        <parameter name="serverRoot">
+            <longdesc lang="en">
+                Define an alternate initial ServerRoot
+            </longdesc>
+            <shortdesc lang="en">
+                Initial ServerRoot
+            </shortdesc>
+	    <content type="string" default="/etc/httpd"/>
+        </parameter>
+
+        <parameter name="serverConfigFile">
+            <longdesc lang="en">
+                Define an alternate ServerConfigFile
+            </longdesc>
+            <shortdesc lang="en">
+                Initial ServerConfigFile
+            </shortdesc>
+            <content type="string" default="conf/httpd.conf"/>
+        </parameter>
+
+        <parameter name="service_name" inherit="service%name">
+            <longdesc lang="en">
+	    	Inherit the service name.  We need to know
+		the service name in order to determine file
+		systems and IPs for this service.
+            </longdesc>
+            <shortdesc lang="en">
+	    	Inherit the service name.
+            </shortdesc>
+	    <content type="string"/>
+        </parameter>
+
+    </parameters>
+
+    <actions>
+        <action name="start" timeout="0"/>
+	<action name="stop" timeout="0"/>
+
+	<!-- Checks to see if it''s mounted in the right place -->
+	<action name="status" interval="1m" timeout="10"/>
+	<action name="monitor" interval="1m" timeout="10"/>
+
+	<!-- Checks to see if we can read from the mountpoint -->
+	<action name="status" depth="10" timeout="30" interval="5m"/>
+	<action name="monitor" depth="10" timeout="30" interval="5m"/>
+
+	<action name="meta-data" timeout="0"/>
+	<action name="verify-all" timeout="0"/>
+    </actions>
+
+    <special tag="rgmanager">
+    </special>
+</resource-agent>
/cvs/cluster/cluster/rgmanager/src/resources/utils/httpd-parse-config.pl,v  -->  standard output
revision 1.1
--- cluster/rgmanager/src/resources/utils/httpd-parse-config.pl
+++ -	2006-08-31 15:01:10.984099000 +0000
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+##
+##  This script removes <IfDefine foo> sections from the
+##  Apache httpd.conf file. This is quite useful because we
+##  don't have any direct access to the parsed configuration
+##  file of the httpd server.
+##
+##  Usage: ./httpd-parse-config.pl -Dfoo1 -Dfoo2 < httpd.conf
+##         where fooX are defines as passed to the httpd server
+##
+##  Note:  All whitespace characters at the beginning and end 
+##         of lines are removed.
+##
+use strict;
+
+my @defines = ();
+## Default behaviour is to show all lines when we are not
+## in the <IfDefine foo> sections.
+my @show = (1);
+
+sub testIfDefine($) {
+	my $param = $1;
+	my $positiveTest = 1;
+	if ($param =~ /^!(.*)$/) {
+		$param = $1;
+		$positiveTest = 0;
+	}
+
+	foreach my $def (@defines) {
+		if ($def eq $param) {
+			return $positiveTest;
+		}
+	}
+
+	return (1-$positiveTest);	
+}
+
+foreach my $arg (@ARGV) {
+	if ($arg =~ /^-D(.*)$/) {
+		push(@defines, $1);
+	}
+}
+
+## Parse config file and remove IfDefine sections 
+while (my $line = <STDIN>) {
+	chomp($line);
+	$line =~ s/^\s*(.*?)\s*$/$1/;
+	if ($line =~ /<IfDefine (.*)>/) {
+		if (testIfDefine($1) == 1) {
+			if ($show[$#show] == 1) {
+				push (@show, 1);
+			} else {
+				push (@show, 0);
+			}
+		} else {
+			push (@show, 0);
+		}
+	} elsif ($line =~ /<\/IfDefine>/) {
+		pop(@show);
+	} elsif ($show[$#show] == 1) {
+		print $line, "\n";
+	}
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]