treewide: change /sbin/sh hashbangs to /bin/sh
[unleashed-userland.git] / components / web / apache24 / Solaris / http-apache24
blobf753782677ce2560cec400833e5d24246d66bdec
1 #!/bin/sh
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
23 # Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
26 . /lib/svc/share/smf_include.sh
28 APACHE_VERSION=
29 APACHE_USR_ROOT=/usr/apache2
30 APACHE_ETC_ROOT=/etc/apache2
31 APACHE_VAR_ROOT=/var/apache2
33 #if startup options contain multiple arguments separated by a blank,
34 #then they should be specified as below
35 #e.g., %> svccfg -s apache24 setprop 'httpd/startup_options=("-f" "/etc/apache2/2.4/new.conf")'
37 STARTUP_OPTIONS=
39 SERVER_TYPE=prefork
40 PLATFORM_DIR=
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=""
50 return
52 return
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}
63 APACHE_USER_ENVVARS=${APACHE_ETC_ROOT}/envvars
65 getprop httpd/enable_64bit
66 if [ "${PROPVAL}" != "" ] ; then
67 case ${PROPVAL} in
68 true|1)
69 # Check if the system architecture supports 64-bit applications
70 PLATFORM=`isainfo -b`
71 if [ "${PLATFORM}" != "64" ]; then
72 echo "This system is not capable of supporting 64-bit applications."
73 echo "Set \"enable_64bit\" property value to \"false\" to start the 32-bit server."
74 exit $SMF_EXIT_ERR_CONFIG
77 # 64 bit Apache
78 PLATFORM_DIR=::ISAINFO::
80 false|0)
81 # 32 bit Apache
82 PLATFORM_DIR=
85 # Invalid value for "bitness"
86 echo "\"bitness\" property value is invalid. Starting the server in 32-bit mode"
87 PLATFORM_DIR=
89 esac
92 APACHE_HOME=${APACHE_USR_ROOT}
93 APACHE_BIN=${APACHE_HOME}/bin${PLATFORM_DIR}
95 getprop httpd/startup_options
96 if [ "${PROPVAL}" != "" ] ; then
97 echo startupoptions set
98 echo val=${PROPVAL}
99 STARTUP_OPTIONS="${PROPVAL} -k"
102 getprop httpd/server_type
103 if [ "${PROPVAL}" != "" ] ; then
104 SERVER_TYPE=${PROPVAL}
107 case ${SERVER_TYPE} in
108 prefork)
109 # If HTTPD value is set in
110 # /etc/apache2/<version>/envvars file
111 # delete the line so that it defaults to prefork
112 # type
113 ALREADY_SET=`grep "HTTPD=" ${APACHE_USER_ENVVARS}`
114 if [ "${ALREADY_SET}" != "" ]; then
115 sed -e '/^HTTPD=/ d' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
116 cp ${APACHE_USER_ENVVARS}.new ${APACHE_USER_ENVVARS}
117 rm ${APACHE_USER_ENVVARS}.new
120 worker)
121 # set HTTPD value to httpd.worker within
122 # /etc/apache2/<version>/envvars file
123 ALREADY_SET=`grep "HTTPD=" ${APACHE_USER_ENVVARS}`
124 if [ "${ALREADY_SET}" != "" ]; then
125 sed -e '/^HTTPD=/c\
126 HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
127 else
128 sed -e '$a\
129 HTTPD='${APACHE_BIN}'/httpd.worker' ${APACHE_USER_ENVVARS} > ${APACHE_USER_ENVVARS}.new
132 cp ${APACHE_USER_ENVVARS}.new ${APACHE_USER_ENVVARS}
133 rm ${APACHE_USER_ENVVARS}.new
136 if [ "x${APACHE_VERSION}" != "x" ]; then
137 echo "Unknown server_type"
138 exit $SMF_EXIT_ERR_CONFIG
141 esac
145 case "$1" in
146 start)
147 cmd="start"
149 refresh)
150 cmd="graceful"
152 stop)
153 cmd="stop"
156 echo "Usage: $0 {start|stop|refresh}"
157 exit $SMF_EXIT_ERR_CONFIG
159 esac
161 APACHE_USER_ENVVARS="${APACHE_USER_ENVVARS}" ${APACHE_BIN}/apachectl ${STARTUP_OPTIONS} ${cmd} 2>&1
163 if [ $? -ne 0 ]; then
164 echo "Server failed to start. Check the error log (defaults to ${APACHE_VAR_ROOT}/logs/error_log) for more information, if any."
165 exit $SMF_EXIT_ERR_FATAL
168 exit $SMF_EXIT_OK