All pastes #971737 Raw Edit

Someone

public text v1 · immutable
·published 2008-04-04 22:58 UTC
rendered paste body
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

opts="configtest fullstatus graceful gracefulstop modules reload vhosts"

depend() {
	need net
	use mysql dns logger netmount postgresql
	after sshd
}

configtest() {
	ebegin "Checking Apache Configuration"
	checkconfig
	eend $?
}

checkconfd() {
	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#/}" = "${CONFIGFILE}" ] && 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}"

	APACHE2="/usr/sbin/apache2"
}

checkconfig() {
	checkconfd || return 1

	${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

	${APACHE2} ${APACHE2_OPTS} -k start
	eend $?
}

stop() {
	checkconfd || return 1
	ebegin "Stopping apache2"
	${APACHE2} ${APACHE2_OPTS} -k stop
	eend $?
}

reload() {
	RELOAD_TYPE="${RELOAD_TYPE:-graceful}"

	checkconfig || return 1
	service_started "${SVCNAME}" || return

	if [ "${RELOAD_TYPE}" = "restart" ]; then
		ebegin "Restarting apache2"
		${APACHE2} ${APACHE2_OPTS} -k restart
		eend $?
	elif [ "${RELOAD_TYPE}" = "graceful" ]; then
		ebegin "Gracefully restarting apache2"
		${APACHE2} ${APACHE2_OPTS} -k graceful
		eend $?
	else
		eerror "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit /etc/conf.d/apache2"
	fi
}

graceful() {
	checkconfig || return 1
	service_started "${SVCNAME}" || return
	ebegin "Gracefully restarting apache2"
	${APACHE2} ${APACHE2_OPTS} -k graceful
	eend $?
}

gracefulstop() {
	checkconfig || return 1

	# zap!
	if service_started "${SVCNAME}"; then
		mark_service_stopped "${SVCNAME}"
	fi

	ebegin "Gracefully stopping apache2"
	${APACHE2} ${APACHE2_OPTS} -k gracefulstop
	eend $?
}

modules() {
	checkconfig || return 1

	${APACHE2} ${APACHE2_OPTS} -M 2>&1
}

vhosts() {
       checkconfig || return 1

       ${APACHE2} ${APACHE2_OPTS} -S 2>&1
}

fullstatus() {
	LYNX="${LYNX:-lynx -dump}"
	STATUSURL="${STATUSURL:-http://localhost/server-status}"

	if ! type -p ${LYNX} 2>&1 >/dev/null; then
		eerror "lynx not found! you need to emerge www-client/lynx"
	else
		${LYNX} ${STATUSURL}
	fi
}