15771644 SUNBT7143713 RFE: allow multiple Apache 2.2 instances to be run
authorPetr Sumbera <petr.sumbera@oracle.com>
Thu, 06 Jun 2013 01:58:08 -0700
changeset 1331 0d14e812ca53
parent 1330 2a50bc2a23b0
child 1332 6ba033a6eae2
15771644 SUNBT7143713 RFE: allow multiple Apache 2.2 instances to be run
components/apache2/Solaris/apache2.1m.sunman
components/apache2/Solaris/http-apache22
components/apache2/patches/apachectl.patch
--- a/components/apache2/Solaris/apache2.1m.sunman	Thu Jun 06 01:58:08 2013 -0700
+++ b/components/apache2/Solaris/apache2.1m.sunman	Thu Jun 06 01:58:08 2013 -0700
@@ -1,6 +1,6 @@
 '\" te
-.\" Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
-.TH apache2 1M "May 2011" "SunOS 5.11" "System Administration Commands"
+.\" Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+.TH apache2 1M "May 2013" "SunOS 5.12" "System Administration Commands"
 .SH NAME
 apache2 \- Apache HTTP Server Version 2 overview
 .SH SYNOPSIS
@@ -19,6 +19,28 @@
 .LP
 Both 32-bit and 64-bit versions of the servers are installed. It also
 includes two of the most popular MPMs - Prefork and Worker.
+.sp
+Apache 2 can be enabled by authorized user within the service
+management facility (SMF), using the following fault management
+resource identifier (FMRI):
+.sp
+.in +2
+.nf
+svc:/network/http:apache22
+.fi
+.in -2
+.sp
+Available SMF properties are listed in the following table:
+.sp
+.TS
+tab(^G) allbox;
+cw(2.750000i)| cw(2.750000i)
+lw(2.750000i)| lw(2.750000i).
+SMF Property Name^Value 
+httpd/server_type^prefork (default) or worker 
+httpd/enable_64bit^true or false(default)
+httpd/startup_options^valid apachectl options
+.TE
 .SH FILES
 .sp
 .LP
@@ -65,6 +87,10 @@
 .RS 4n
 Contains server configuration files. A newly-installed server
 contains a default \fBhttpd.conf\fR file. This is the main configuration file.
+.sp
+If there is need to use different main configuration file (e.g. to run
+multiple Apache 2 instances), it's possible by providing Apache '-f'
+option via SMF property httpd/startup_options.
 .RE
 
 .sp
@@ -95,6 +121,11 @@
 File for specifying the environment settings which the server uses at
 startup. This is the user-editable version of the 
 /usr/apache2/[version]/bin/envvars file. 
+.sp
+Note that this is default path to envvars file only in case where main
+configuration file is in directory /etc/apache2/[version]/2.2/. If this
+is not the case Apache 2 will look for envvars file in the same
+directory where is main configuration file.
 .RE
 
 .sp
@@ -383,18 +414,67 @@
 configuration in the \fBhttpd.conf\fR file.
 .RE
 
+.SH EXAMPLES
+.LP
+\fBExample 1 \fRTo enable 64-bit server
+.sp
+
+.in +2
+.nf
+# \fBsvccfg -s apache22 setprop httpd/enable_64bit=false\fR
+# \fBsvcadm refresh apache22\fR
+# \fBsvcadm enable apache22\fR
+.fi
+.in -2
+.sp
+
+.LP
+\fBExample 2 \fRTo switch to worker server type
+.sp
+
+.in +2
+.nf
+# \fBsvccfg -s apache22 setprop httpd/server_type=worker\fR
+# \fBsvcadm refresh apache22\fR
+# \fBsvcadm restart apache22\fR
+.fi
+.in -2
+.sp
+
+.LP
+\fBExample 3 \fRCreate new SMF apache instance
+.sp
+.LP
+This expects that valid configuration exists in
+/var/myapache/httpd.conf and it has altered all relevant directives
+against default apache instance (e.g. PidFile, Listen, DocumentRoot,
+ErrorLog and CustomLog).
+.sp
+.in +2
+.nf
+# \fBcp /lib/svc/manifest/network/http-apache22.xml my-apache22.xml\fR
+.sp
+Edit my-apache22.xml and rename instance name to my-apache22.
+
+# \fBsvccfg import my-apache22.xml\fR
+# \fBsvccfg -s my-apache22 setprop httpd/startup_options=\\("-f" "/var/myapache/httpd.conf"\\)\fR
+# \fBsvcadm refresh my-apache22\fR
+.fi
+.in -2
+.sp
+
 .SH SEE ALSO
 .sp
 .LP
 \fBattributes(5)\fR, \fBhttpd(8)\fR, apachectl(8)
 .sp
 .LP
-http://www.apache.org
+http://httpd.apache.org/docs/
 .SH NOTES
 .sp
 .LP
 In addition to the documentation and man pages included with Solaris,
-more information is available at http://www.apache.org\&.
+more information is available at http://httpd.apache.org/\&.
 .sp
 .LP
 The Apache 2 man pages are provided with the programming modules. To
--- a/components/apache2/Solaris/http-apache22	Thu Jun 06 01:58:08 2013 -0700
+++ b/components/apache2/Solaris/http-apache22	Thu Jun 06 01:58:08 2013 -0700
@@ -20,7 +20,7 @@
 # CDDL HEADER END
 #
 #
-# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
 #
 
 . /lib/svc/share/smf_include.sh
@@ -52,6 +52,20 @@
     return
 }
 
+# Check whether alternate config file was specified using option -f.
+# If it's the case, Apache will search in the same directory for
+# availability of environment file.
+envvars_path_update() {
+    eval "set -- $1"
+    while [ $# -gt 0 ]; do
+        case "$1" in
+          -f) APACHE_USER_ENVVARS=`dirname "${2:-}"`/envvars; break;;
+          -f*) APACHE_USER_ENVVARS=`dirname "${1#-f}"`/envvars; break;;
+        esac
+        shift
+    done
+}
+
 APACHE_VERSION=`echo ${SMF_FMRI} | sed 's/[^0-9]//g;s/./\.&/g;s/^\.//'` 
 if [ "x${APACHE_VERSION}" != "x" ]; then
     echo "Apache version is ${APACHE_VERSION}"
@@ -97,6 +111,7 @@
 	echo startupoptions set
 	echo val=${PROPVAL}
 	STARTUP_OPTIONS="${PROPVAL} -k"
+        envvars_path_update "${PROPVAL}"
 fi
 
 getprop httpd/server_type
@@ -106,31 +121,10 @@
 
 case ${SERVER_TYPE} in
 prefork)
-	# If HTTPD value is set in
-	# /etc/apache2/<version>/envvars file
-	# delete the line so that it defaults to prefork 
-	# type
-	ALREADY_SET=`grep "HTTPD=" ${APACHE_USER_ENVVARS}`
-	if [ "${ALREADY_SET}" != "" ]; then
-		sed -e '/^HTTPD=/ d' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
-		cp ${APACHE_USER_ENVVARS}.new ${APACHE_USER_ENVVARS}
-		rm ${APACHE_USER_ENVVARS}.new
-	fi
+	HTTPD=${APACHE_BIN}/httpd
 	;;
 worker)
-	# set HTTPD value to httpd.worker within 
-	# /etc/apache2/<version>/envvars file
-	ALREADY_SET=`grep "HTTPD=" ${APACHE_USER_ENVVARS}`
-	if [ "${ALREADY_SET}" != "" ]; then
-		sed -e '/^HTTPD=/c\
-HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
-	else
-		sed -e '$a\
-HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
-	fi
-
-	cp ${APACHE_USER_ENVVARS}.new ${APACHE_USER_ENVVARS}
-	rm ${APACHE_USER_ENVVARS}.new
+	HTTPD=${APACHE_BIN}/httpd.worker
 	;;
 *)
         if [ "x${APACHE_VERSION}" != "x" ]; then
@@ -158,7 +152,7 @@
 	;;
 esac
 
-APACHE_USER_ENVVARS="${APACHE_USER_ENVVARS}" ${APACHE_BIN}/apachectl ${STARTUP_OPTIONS} ${cmd} 2>&1
+HTTPD="${HTTPD}" APACHE_USER_ENVVARS="${APACHE_USER_ENVVARS}" ${APACHE_BIN}/apachectl ${STARTUP_OPTIONS} ${cmd} 2>&1
 
 if [ $? -ne 0 ]; then
     echo "Server failed to start. Check the error log (defaults to ${APACHE_VAR_ROOT}/logs/error_log) for more information, if any."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/apache2/patches/apachectl.patch	Thu Jun 06 01:58:08 2013 -0700
@@ -0,0 +1,14 @@
+Allows SMF method to override Apache binary to start and thus select if
+we want prefork/worker Apache MPM.
+
+--- support/apachectl.in	Tue Jul 11 20:38:44 2006
++++ support/apachectl.in	Tue May 14 07:40:03 2013
[email protected]@ -41,7 +41,7 @@
+ # --------------------                              --------------------
+ # 
+ # the path to your httpd binary, including options if necessary
+-HTTPD='@[email protected]/@[email protected]'
++HTTPD=${HTTPD:[email protected][email protected]/@[email protected]}
+ #
+ # pick up any necessary environment variables
+ if test -f @[email protected]/envvars; then