#!/bin/ksh93 # # SMF httpd startup file: /lib/svc/method/http-apache22 # Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. # Portions Copyright 2012 Jens Elkner . /lib/svc/share/smf_include.sh APACHE_VERSION= APACHE_USR_ROOT=/usr/apache2 APACHE_ETC_ROOT=/etc/apache2 APACHE_VAR_ROOT=/var/apache2 DEFAULT_STATUSURL='http://localhost:80/server-status' #if startup options contain multiple arguments separated by a blank, #then they should be specified as below #e.g., %> svccfg -s apache22 setprop 'httpd/startup_options=("-f" "/etc/apache2/2.2/new.conf")' # STARTUP_OPTIONS= SERVER_TYPE=prefork PLATFORM_DIR= # subdirs are expected to follow the format $major.$minor if [[ -z ${SMF_FMRI} ]]; then VERS=${ ls -1 ${APACHE_USR_ROOT} | sort -t. -n -k1,1 -k2,2 | tail -1; } VERS=${VERS//.} SMF_FMRI="svc:/network/http:apache${VERS}" print "SMF_FMRI is not set. Using SMF_FMRI=${SMF_FMRI}" fi getprop() { PROPVAL='' svcprop -q -p $1 ${SMF_FMRI} if (( $? == 0 )) ; then PROPVAL=${ svcprop -p $1 ${SMF_FMRI}; } [[ ${PROPVAL} == '""' ]] && PROPVAL='' fi } # This is brain damaged anyway. Because it is more likely that the minor # version grows above 9 than the major number, we just add a '.' after the # first digit. APACHE_VERSION=${SMF_FMRI//[^0-9]} APACHE_VERSION="${APACHE_VERSION/@([0-9])/\1\.}" if [[ -n ${APACHE_VERSION} ]]; then print "Apache version is ${APACHE_VERSION}" APACHE_USR_ROOT=${APACHE_USR_ROOT}/${APACHE_VERSION} APACHE_ETC_ROOT=${APACHE_ETC_ROOT}/${APACHE_VERSION} APACHE_VAR_ROOT=${APACHE_VAR_ROOT}/${APACHE_VERSION} fi getprop httpd/startup_options [[ -n ${PROPVAL} ]] && STARTUP_OPTIONS="${PROPVAL}" PLATFORM_DIR= getprop httpd/enable_64bit if [[ -n ${PROPVAL} ]] ; then case ${PROPVAL} in true|1) # Check if the system architecture supports 64-bit applications PLATFORM=${ isainfo -b ; } if [[ ${PLATFORM} != '64' ]]; then print -u2 ' This system is not capable of supporting 64-bit applications. Set "enable_64bit" property value to "false" to start the 32-bit server.' exit $SMF_EXIT_ERR_CONFIG fi # 64 bit Apache PLATFORM_DIR=/amd64 STARTUP_OPTIONS+=' -D 64bit' ;; false|0) # 32 bit Apache ;; *) # Invalid value for "bitness" print -u2 '"bitness" property value is invalid. Starting the server in 32-bit mode' ;; esac fi APACHE_HOME=${APACHE_USR_ROOT} APACHE_BIN=${APACHE_HOME}/bin${PLATFORM_DIR} if [[ -d ${APACHE_USR_ROOT}/lib${PLATFORM_DIR} ]]; then if [[ -n ${PLATFORM_DIR} && -n ${LD_LIBRARY_PATH_64} ]]; then LD_LIBRARY_PATH_64="${APACHE_USR_ROOT}/lib${PLATFORM_DIR}:${LD_LIBRARY_PATH_64}" elif [[ -z ${LD_LIBRARY_PATH} ]]; then export LD_LIBRARY_PATH="${APACHE_USR_ROOT}/lib${PLATFORM_DIR}" else export LD_LIBRARY_PATH="${APACHE_USR_ROOT}/lib${PLATFORM_DIR}:${LD_LIBRARY_PATH}" fi fi getprop httpd/server_type [[ -n ${PROPVAL} ]] && SERVER_TYPE=${PROPVAL} case "${SERVER_TYPE}" in prefork) HTTPD="${APACHE_BIN}/httpd" ;; worker) HTTPD="${APACHE_BIN}/httpd.worker" ;; *) if [[ -n ${APACHE_VERSION} ]]; then print -u2 'Unknown server_type' exit ${SMF_EXIT_ERR_CONFIG} fi ;; esac [[ -n ${APACHE_USER_ENVVARS} && -r ${APACHE_USER_ENVVARS} ]] && \ . "${APACHE_USER_ENVVARS}" case "$1" in start) ULIMIT_MAX_FILES=${ ulimit -H -n; } [[ -n ${ULIMIT_MAX_FILES} ]] && ulimit -S -n ${ULIMIT_MAX_FILES} cmd='-k start' ;; refresh) cmd='-k graceful' ;; stop|restart|graceful-stop) cmd="-k $1" ;; configtest|test) cmd='-t' ;; status|fullstatus) LYNX=${ whence lynx; } [[ -z ${LYNX} ]] && LYNX=${ whence links; } if [[ -n ${LYNX} && -x ${LYNX} ]]; then getprop httpd/status_url STATUSURL=${PROPVAL:-${DEFAULT_STATUSURL}} if [[ $1 == 'status' ]]; then "${LYNX}" -dump "${STATUSURL}" | \ awk '/process$/ { print; exit } { print }' else "${LYNX}" -dump "${STATUSURL}" fi exit $? else print -u2 'lynx/links not found' exit ${SMF_EXIT_ERR_FATAL} fi ;; *) print "Usage: $0 {start|stop|refresh|restart|graceful-stop|configtest|status|fullstatus}" exit ${SMF_EXIT_ERR_CONFIG} ;; esac print "${HTTPD} ${STARTUP_OPTIONS} ${cmd}" APACHE_USER_ENVVARS="${APACHE_USER_ENVVARS}" ${HTTPD} ${STARTUP_OPTIONS} ${cmd} RES=$? if [[ ${cmd} == '-t' ]]; then exit $RES fi if (( $RES != 0 )); then print -u2 "Server failed to start (error code ${RES}). Check the error log (usually defaults to ${APACHE_VAR_ROOT}/logs/error_log or /var/log/httpd/error.log) for more information, if any." exit ${SMF_EXIT_ERR_FATAL} fi exit ${SMF_EXIT_OK}