#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
opts="${opts} reload configtest"
# this next comment is important, don't remove it - it has to be somewhere in
# the init script to kill off a warning that doesn't apply to us
# svc_start svc_stop
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.conf}"
[ ${CONFIGFILE:0:1} != "/" ] && CONFIGFILE="${SERVERROOT}/${CONFIGFILE}"
if [ ! -r "${CONFIGFILE}" ]; then
eerror "Unable to read configuration file: ${CONFIGFILE}"
return 1
fi
# check to see if the old config files exist and aren't used
if [[ "${CONFIGFILE}" != "/etc/apache2/conf/apache2.conf" &&
-e "/etc/apache2/conf/apache2.conf" ]]; then
eerror "Found old apache2.conf in /etc/apache2/conf. Configuration locations \n have moved, please check ${CONFIGFILE} to make sure it is correct, \n and remove /etc/apache2/conf/apache2.conf.\n\n Please see http://www.gentoo.org/doc/en/apache-upgrading.xml\n for more information."
return 1
fi
[ -n "${SERVERROOT}" ] && APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}"
[ -n "${CONFIGFILE}" ] && APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
[ -n "${STARTUPERRORLOG}" ] && APACHE2_OPTS="${APACHE2_OPTS} -E ${STARTUPERRORLOG}"
# set a sane default for KEEPENV and OLDENV
KEEPENV=${KEEPENV:-PATH}
OLDENV=
for env_var in ${KEEPENV}; do
OLDENV="${OLDENV} ${env_var}=`printenv ${env_var}`"
done
APACHE2="env -i ${OLDENV} /usr/sbin/apache2"
$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
[ -f /usr/lib/apache2/build/envvars ] && . /usr/lib/apache2/build/envvars
${APACHE2} ${APACHE2_OPTS} -k start
eend $?
}
stop() {
checkconfig || return 1
ebegin "Stopping apache2"
${APACHE2} ${APACHE2_OPTS} -k stop
eend $?
}
reload() {
if ! service_started "${myservice}" ; then
eerror "Apache is not running! Please start it before trying to reload it."
else
checkconfig || return 1
ebegin "Reloading apache2"
${APACHE2} ${APACHE2_OPTS} -k graceful
eend $?
fi
}