components/apache2/Solaris/http-apache22
changeset 278 77b380ba9d84
child 716 2d2eb53223b2
equal deleted inserted replaced
277:12ebd29ad46c 278:77b380ba9d84
       
     1 #!/sbin/sh
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 #
       
    23 # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
       
    24 #
       
    25 
       
    26 . /lib/svc/share/smf_include.sh
       
    27 
       
    28 APACHE_VERSION=
       
    29 APACHE_USR_ROOT=/usr/apache2
       
    30 APACHE_ETC_ROOT=/etc/apache2
       
    31 APACHE_VAR_ROOT=/var/apache2
       
    32 
       
    33 #if startup options contain multiple arguments separated by a blank,
       
    34 #then they should be specified as below
       
    35 #e.g., %> svccfg -s apache22 setprop 'httpd/startup_options=("-f" "/etc/apache2/2.2/new.conf")' 
       
    36 #
       
    37 STARTUP_OPTIONS=
       
    38 
       
    39 SERVER_TYPE=prefork
       
    40 PLATFORM_DIR=
       
    41 
       
    42 getprop() {
       
    43     PROPVAL=""
       
    44     svcprop -q -p $1 ${SMF_FMRI}
       
    45     if [ $? -eq 0 ] ; then
       
    46         PROPVAL=`svcprop -p $1 ${SMF_FMRI}`
       
    47         if [ "${PROPVAL}" = "\"\"" ] ; then
       
    48             PROPVAL=""
       
    49         fi
       
    50         return
       
    51     fi
       
    52     return
       
    53 }
       
    54 
       
    55 APACHE_VERSION=`echo ${SMF_FMRI} | sed 's/[^0-9]//g;s/./\.&/g;s/^\.//'` 
       
    56 if [ "x${APACHE_VERSION}" != "x" ]; then
       
    57     echo "Apache version is ${APACHE_VERSION}"
       
    58     APACHE_USR_ROOT=${APACHE_USR_ROOT}/${APACHE_VERSION}
       
    59     APACHE_ETC_ROOT=${APACHE_ETC_ROOT}/${APACHE_VERSION}
       
    60     APACHE_VAR_ROOT=${APACHE_VAR_ROOT}/${APACHE_VERSION}
       
    61 fi
       
    62 
       
    63 getprop httpd/enable_64bit
       
    64 if [ "${PROPVAL}" != "" ] ; then
       
    65     case ${PROPVAL} in
       
    66     true|1)
       
    67         # Check if the system architecture supports 64-bit applications
       
    68         PLATFORM=`isainfo -b`
       
    69         if [ "${PLATFORM}" != "64" ]; then
       
    70             echo "This system is not capable of supporting 64-bit applications."
       
    71             echo "Set \"enable_64bit\" property value to \"false\" to start the 32-bit server."
       
    72             exit $SMF_EXIT_ERR_CONFIG
       
    73         fi
       
    74 
       
    75 	# 64 bit Apache
       
    76 	PLATFORM_DIR=::ISAINFO::
       
    77 	;;
       
    78     false|0) 
       
    79 	# 32 bit Apache
       
    80 	PLATFORM_DIR=
       
    81 	;;
       
    82     *)
       
    83 	# Invalid value for "bitness"
       
    84 	echo "\"bitness\" property value is invalid. Starting the server in 32-bit mode"
       
    85 	PLATFORM_DIR=
       
    86 	;;
       
    87     esac
       
    88 fi
       
    89 
       
    90 APACHE_HOME=${APACHE_USR_ROOT}
       
    91 APACHE_BIN=${APACHE_HOME}/bin${PLATFORM_DIR}
       
    92 
       
    93 getprop httpd/startup_options
       
    94 if [ "${PROPVAL}" != "" ] ; then
       
    95 	echo startupoptions set
       
    96 	echo val=${PROPVAL}
       
    97 	STARTUP_OPTIONS="${PROPVAL} -k"
       
    98 fi
       
    99 
       
   100 getprop httpd/server_type
       
   101 if [ "${PROPVAL}" != "" ] ; then
       
   102 	SERVER_TYPE=${PROPVAL}
       
   103 fi
       
   104 
       
   105 case ${SERVER_TYPE} in
       
   106 prefork)
       
   107 	# If HTTPD value is set in
       
   108 	# /etc/apache2/<version>/envvars file
       
   109 	# delete the line so that it defaults to prefork 
       
   110 	# type
       
   111 	ALREADY_SET=`grep "HTTPD=" ${APACHE_ETC_ROOT}/envvars`
       
   112 	if [ "${ALREADY_SET}" != "" ]; then
       
   113 		sed -e '/^HTTPD=/ d' ${APACHE_ETC_ROOT}/envvars > ${APACHE_ETC_ROOT}/envvars.new
       
   114 		cp ${APACHE_ETC_ROOT}/envvars.new ${APACHE_ETC_ROOT}/envvars
       
   115 		rm ${APACHE_ETC_ROOT}/envvars.new
       
   116 	fi
       
   117 	;;
       
   118 worker)
       
   119 	# set HTTPD value to httpd.worker within 
       
   120 	# /etc/apache2/<version>/envvars file
       
   121 	ALREADY_SET=`grep "HTTPD=" ${APACHE_ETC_ROOT}/envvars`
       
   122 	if [ "${ALREADY_SET}" != "" ]; then
       
   123 		sed -e '/^HTTPD=/c\
       
   124 HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_ETC_ROOT}/envvars > ${APACHE_ETC_ROOT}/envvars.new
       
   125 	else
       
   126 		sed -e '$a\
       
   127 HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_ETC_ROOT}/envvars > ${APACHE_ETC_ROOT}/envvars.new
       
   128 	fi
       
   129 
       
   130 	cp ${APACHE_ETC_ROOT}/envvars.new ${APACHE_ETC_ROOT}/envvars
       
   131 	rm ${APACHE_ETC_ROOT}/envvars.new
       
   132 	;;
       
   133 *)
       
   134         if [ "x${APACHE_VERSION}" != "x" ]; then
       
   135             echo "Unknown server_type"
       
   136             exit $SMF_EXIT_ERR_CONFIG
       
   137         fi
       
   138 	;;
       
   139 esac
       
   140 	
       
   141 
       
   142 
       
   143 case "$1" in
       
   144 start)
       
   145 	cmd="start"
       
   146 	;;
       
   147 refresh)
       
   148 	cmd="graceful"
       
   149 	;;
       
   150 stop)
       
   151 	cmd="stop"
       
   152 	;;
       
   153 *)
       
   154 	echo "Usage: $0 {start|stop|refresh}"
       
   155 	exit $SMF_EXIT_ERR_CONFIG
       
   156 	;;
       
   157 esac
       
   158 
       
   159 ${APACHE_BIN}/apachectl ${STARTUP_OPTIONS} ${cmd} 2>&1
       
   160 
       
   161 if [ $? -ne 0 ]; then
       
   162     echo "Server failed to start. Check the error log (defaults to ${APACHE_VAR_ROOT}/logs/error_log) for more information, if any."
       
   163     exit $SMF_EXIT_ERR_FATAL
       
   164 fi
       
   165 
       
   166 exit $SMF_EXIT_OK