#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: 345 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # # Originally from Red Hat distribution, but modified for Debian and # /usr/local by Eric Myers - 24 Sept. 2007 ####################################################################### # Init script function library. This stuff is Red Hat specific, # but if those functions are not found we create our own simple replacements. # (The idea for replacing the functions came from OpenAFS. Thanks guys!) if [ -f /etc/rc.d/init.d/functions ] ; then . /etc/rc.d/init.d/functions else export PATH=/sbin:/bin:/usr/sbin:/usr/bin function echo_success () { echo -n " [ OK ] " ; } function echo_failure () { echo -n " [FAILED] " ; } function echo_warning () { echo -n " [WARNING] " ; } function killproc() { PID=`pidof -s -x -o $$ -o $PPID -o %PPID $1` [ $PID ] && kill $PID ; } fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} export LANG=$HTTPD_LANG # su on Linux seems to need this to be set to work properly export TERM dumb # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=${APACHECTL-"/usr/local/sbin/apachectl"} httpd=${HTTPD-"/usr/local/sbin/httpd"} prog=`basename $httpd` pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 ## Look for any local configuration settings, which override the above # We could even use the system apache2 defaults if nothing else found. if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd elif [ -f /etc/default/httpd ]; then . /etc/default/httpd elif [ 0 = 1 -a -f /etc/default/apache2 ]; then . /etc/default/apache2 echo "${prog}: using apache2 system defaults..." if [ "$NO_START" != "0" -a "$1" != "stop" ]; then [ "$VERBOSE" != no ] && echo "Not starting apache2 - edit /etc/default/apache2 and change NO_START to be 0."; exit 0; fi fi ## # Check for 1.3 configuration, bail if we have it. # check13 () { CONFFILE=/etc/httpd/conf/httpd.conf GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|" GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|" GONE="${GONE}AccessConfig|ResourceConfig)" if [ -f $CONFFILE ]; then if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then echo echo 1>&2 " Apache 1.3 configuration directives found" echo 1>&2 " please read /usr/share/doc/httpd-2.0.54/migration.html" failure "Apache 1.3 config directives test" echo exit 1 fi fi } ## # The semantics of these functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " check13 || exit 1 $apachectl $OPTIONS start RETVAL=$? [ $RETVAL = 0 ] && touch ${lockfile} [ $RETVAL = 0 ] && echo_success || echo_failure echo return $RETVAL } stop() { echo -n $"Stopping $prog: " $apachectl stop RETVAL=$? [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} [ $RETVAL = 0 ] && echo_success || echo_failure echo return $RETVAL } reload() { echo -n $"Reloading $prog: " if ! $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $prog due to configuration syntax error" else killproc $httpd -HUP RETVAL=$? [ $RETVAL = 0 ] && echo_success || echo_failure echo fi echo } # See how we were called, and do it. case "$1" in start) start ;; stop) stop ;; status) PID=`pidof -x -o $$ -o $PPID -o %PPID httpd` if [ "$PID" != "" ]; then echo "Apache httpd is running (pid $PID)." else if [ -f $lockfile ]; then echo "${prog}: server is stopped but lockfile exists." else echo "${prog}: server is stopped." fi fi ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL