#!/sbin/runscript # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 opts="${opts} reload configtest" # TODO # Remove all the enviroment crap, as it's not needed after baselayout 1.12.0. # There are still people using older versions, baselayout 1.12.0 was first # stable with 2006.1, so we need to wait some time before doing that. clear_env_except() { local save_env=$1 shift; curr_env=$(env | sed 's/=.*//') for env_var in ${curr_env}; do local save=0 for save_var in ${save_env}; do if [[ "${env_var}" == "${save_var}" ]]; then save=1 fi done if [[ "${save}" == "0" ]]; then unset_vars="${unset_vars} -u ${env_var}" fi done env ${unset_vars} $@ } depend() { need net use mysql dns logger netmount postgresql after sshd } configtest() { ebegin "Checking Apache Configuration" checkconfig eend $? } checkconfig() { SERVERROOT="${SERVERROOT:-/usr/lib/apache2}" if [ ! -d ${SERVERROOT} ]; then eerror "SERVERROOT does not exist: ${SERVERROOT}" return 1 fi CONFIGFILE="${CONFIGFILE:-/etc/apache2/httpd-backuppc.conf}" [ ${CONFIGFILE:0:1} != "/" ] && CONFIGFILE="${SERVERROOT}/${CONFIGFILE}" if [ ! -r "${CONFIGFILE}" ]; then eerror "Unable to read configuration file: ${CONFIGFILE}" return 1 fi APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}" APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}" [ -n "${STARTUPERRORLOG}" ] && APACHE2_OPTS="${APACHE2_OPTS} -E ${STARTUPERRORLOG}" # set a sane default for KEEPENV KEEPENV=${KEEPENV:-PATH} APACHE2="/usr/sbin/apache2" # TODO kill the environment crap... see note above clear_env_except "${KEEPENV}" ${APACHE2} ${APACHE2_OPTS} -t 1>/dev/null 2>&1 ret=$? if [ $ret -ne 0 ]; then eerror "Apache2 has detected a syntax error in your configuration files:" ${APACHE2} ${APACHE2_OPTS} -t fi return $ret } start() { checkconfig || return 1 ebegin "Starting apache2" [ -f /var/log/apache2/ssl_scache ] && rm /var/log/apache2/ssl_scache # TODO kill the environment crap... see note above clear_env_except "${KEEPENV}" /sbin/start-stop-daemon --start --exec ${APACHE2} --pidfile /var/run/apache2-backuppc.pid -- ${APACHE2_OPTS} -k start eend $? } stop() { checkconfig || return 1 ebegin "Stopping apache2" /sbin/start-stop-daemon --stop --retry -TERM/5/-TERM/5/-KILL/5 --exec ${APACHE2} --pidfile /var/run/apache2-backuppc.pid eend $? } reload() { checkconfig || return 1 ebegin "Doing a graceful restart of apache2" /sbin/start-stop-daemon --stop --signal USR1 --exec ${APACHE2} --pidfile /var/run/apache2-backuppc.pid eend $? }