123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #!/usr/bin/openrc-run
- # Copyright 1999-2016 Gentoo Foundation
- # Distributed under the terms of the GNU General Public License v2
- extra_commands="configtest modules virtualhosts"
- extra_started_commands="configdump fullstatus graceful gracefulstop reload"
- description_configdump="Dumps the configuration of the runing apache server. Requires server-info to be enabled and www-client/lynx."
- description_configtest="Run syntax tests for configuration files."
- description_fullstatus="Gives the full status of the server. Requires lynx and server-status to be enabled."
- description_graceful="A graceful restart advises the children to exit after the current request and reloads the configuration."
- description_gracefulstop="A graceful stop advises the children to exit after the current request and stops the server."
- description_modules="Dump a list of loaded Static and Shared Modules."
- description_reload="Kills all children and reloads the configuration."
- description_virtualhosts="Show the settings as parsed from the config file (currently only shows the virtualhost settings)."
- description_stop="Kills all children and stops the server."
- # Apply default values for some conf.d variables.
- PIDFILE="${PIDFILE:-/run/httpd/httpd.pid}"
- TIMEOUT=${TIMEOUT:-15}
- SERVERROOT="${SERVERROOT:-/usr/lib/httpd}"
- CONFIGFILE="${CONFIGFILE:-/etc/httpd/conf/httpd.conf}"
- LYNX="${LYNX:-lynx -dump}"
- STATUSURL="${STATUSURL:-http://localhost/server-status}"
- RELOAD_TYPE="${RELOAD_TYPE:-graceful}"
- # Append the server root and configuration file parameters to the
- # user's APACHE2_OPTS.
- APACHE2_OPTS="${APACHE2_OPTS} -d ${SERVERROOT}"
- APACHE2_OPTS="${APACHE2_OPTS} -f ${CONFIGFILE}"
- # The path to the apache2 binary.
- APACHE2="/usr/bin/apachectl"
- depend() {
- need net
- use dns entropy logger mysql netmount postgresql
- after sshd
- }
- configtest() {
- ebegin "Checking ${SVCNAME} configuration"
- checkconfig
- eend $?
- }
- checkconfd() {
- if [ ! -d ${SERVERROOT} ]; then
- eerror "SERVERROOT does not exist: ${SERVERROOT}"
- return 1
- fi
- }
- checkconfig() {
- checkpath --directory /run/httpd
- checkconfd || return 1
- OUTPUT=$( ${APACHE2} ${APACHE2_OPTS} -t 2>&1 )
- ret=$?
- if [ $ret -ne 0 ]; then
- eerror "${SVCNAME} has detected an error in your setup:"
- printf "%s\n" "${OUTPUT}"
- fi
- return $ret
- }
- start() {
- checkconfig || return 1
- if [ -n "${STARTUPERRORLOG}" ] ; then
- # We must make sure that we only append to APACHE2_OPTS
- # in start() and not in stop() or anywhere else that may
- # be executed along with start(), see bug #566726.
- APACHE2_OPTS="${APACHE2_OPTS} -E ${STARTUPERRORLOG}"
- fi
- ebegin "Starting ${SVCNAME}"
- # Use start stop daemon to apply system limits #347301
- start-stop-daemon --start -- ${APACHE2} ${APACHE2_OPTS} -k start
- local i=0 retval=1
- while [ $i -lt ${TIMEOUT} ] ; do
- if [ -e "${PIDFILE}" ] ; then
- retval=0
- break
- fi
- sleep 1 && i=$(expr $i + 1)
- done
- eend ${retval}
- }
- stop() {
- if [ "${RC_CMD}" = "restart" ]; then
- checkconfig || return 1
- fi
- PID=$(cat "${PIDFILE}" 2>/dev/null)
- if [ -z "${PID}" ]; then
- einfo "${SVCNAME} not running (no pid file)"
- return 0
- fi
- ebegin "Stopping ${SVCNAME}"
- ${APACHE2} ${APACHE2_OPTS} -k stop
- local i=0 retval=0
- while ( test -f "${PIDFILE}" || pgrep -P ${PID} httpd >/dev/null ) \
- && [ $i -lt ${TIMEOUT} ]; do
- sleep 1 && i=$(expr $i + 1)
- done
- [ -e "${PIDFILE}" ] && retval=1
- eend ${retval}
- }
- reload() {
- checkconfig || return 1
- if [ "${RELOAD_TYPE}" = "restart" ]; then
- ebegin "Restarting ${SVCNAME}"
- ${APACHE2} ${APACHE2_OPTS} -k restart
- eend $?
- elif [ "${RELOAD_TYPE}" = "graceful" ]; then
- ebegin "Gracefully restarting ${SVCNAME}"
- ${APACHE2} ${APACHE2_OPTS} -k graceful
- eend $?
- else
- eerror "${RELOAD_TYPE} is not a valid RELOAD_TYPE. Please edit /etc/conf.d/${SVCNAME}"
- fi
- }
- graceful() {
- checkconfig || return 1
- ebegin "Gracefully restarting ${SVCNAME}"
- ${APACHE2} ${APACHE2_OPTS} -k graceful
- eend $?
- }
- gracefulstop() {
- checkconfig || return 1
- ebegin "Gracefully stopping ${SVCNAME}"
- ${APACHE2} ${APACHE2_OPTS} -k graceful-stop
- eend $?
- }
- modules() {
- checkconfig || return 1
- ${APACHE2} ${APACHE2_OPTS} -M 2>&1
- }
- fullstatus() {
- if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then
- eerror "lynx not found! you need to emerge www-client/lynx"
- else
- ${LYNX} ${STATUSURL}
- fi
- }
- virtualhosts() {
- checkconfig || return 1
- ${APACHE2} ${APACHE2_OPTS} -S
- }
- configdump() {
- INFOURL="${INFOURL:-http://localhost/server-info}"
- checkconfd || return 1
- if ! command -v $(set -- ${LYNX}; echo $1) 2>&1 >/dev/null; then
- eerror "lynx not found! you need to emerge www-client/lynx"
- else
- echo "${APACHE2} started with '${APACHE2_OPTS}'"
- for i in config server list; do
- ${LYNX} "${INFOURL}/?${i}" | sed '/Apache Server Information/d;/^[[:space:]]\+[_]\+$/Q'
- done
- fi
- }
- # vim: ts=4 filetype=gentoo-init-d
|