| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # httpd Startup script for the Apache HTTP Server |
|---|
| 4 | # |
|---|
| 5 | # chkconfig: - 85 15 |
|---|
| 6 | # description: The Apache HTTP Server is an efficient and extensible \ |
|---|
| 7 | # server implementing the current HTTP standards. |
|---|
| 8 | # processname: httpd |
|---|
| 9 | # config: /etc/httpd/conf/httpd.conf |
|---|
| 10 | # config: /etc/sysconfig/httpd |
|---|
| 11 | # pidfile: /var/run/httpd/httpd.pid |
|---|
| 12 | # |
|---|
| 13 | ### BEGIN INIT INFO |
|---|
| 14 | # Provides: httpd |
|---|
| 15 | # Required-Start: $local_fs $remote_fs $network $named openafs-client crond |
|---|
| 16 | # Required-Stop: $local_fs $remote_fs $network |
|---|
| 17 | # Should-Start: distcache |
|---|
| 18 | # Short-Description: start and stop Apache HTTP Server |
|---|
| 19 | # Description: The Apache HTTP Server is an extensible server |
|---|
| 20 | # implementing the current HTTP standards. |
|---|
| 21 | ### END INIT INFO |
|---|
| 22 | |
|---|
| 23 | # Source function library. |
|---|
| 24 | . /etc/rc.d/init.d/functions |
|---|
| 25 | |
|---|
| 26 | if [ -f /etc/sysconfig/httpd ]; then |
|---|
| 27 | . /etc/sysconfig/httpd |
|---|
| 28 | fi |
|---|
| 29 | |
|---|
| 30 | # Start httpd in the C locale by default. |
|---|
| 31 | HTTPD_LANG=${HTTPD_LANG-"C"} |
|---|
| 32 | |
|---|
| 33 | # This will prevent initlog from swallowing up a pass-phrase prompt if |
|---|
| 34 | # mod_ssl needs a pass-phrase from the user. |
|---|
| 35 | INITLOG_ARGS="" |
|---|
| 36 | |
|---|
| 37 | # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server |
|---|
| 38 | # with the thread-based "worker" MPM; BE WARNED that some modules may not |
|---|
| 39 | # work correctly with a thread-based MPM; notably PHP will refuse to start. |
|---|
| 40 | |
|---|
| 41 | # Path to the apachectl script, server binary, and short-form for messages. |
|---|
| 42 | apachectl=/usr/sbin/apachectl |
|---|
| 43 | httpd=${HTTPD-/usr/sbin/httpd} |
|---|
| 44 | prog=httpd |
|---|
| 45 | pidfile=${PIDFILE-/var/run/httpd/httpd.pid} |
|---|
| 46 | lockfile=${LOCKFILE-/var/lock/subsys/httpd} |
|---|
| 47 | RETVAL=0 |
|---|
| 48 | STOP_TIMEOUT=${STOP_TIMEOUT-10} |
|---|
| 49 | |
|---|
| 50 | # The semantics of these two functions differ from the way apachectl does |
|---|
| 51 | # things -- attempting to start while running is a failure, and shutdown |
|---|
| 52 | # when not running is also a failure. So we just do it the way init scripts |
|---|
| 53 | # are expected to behave here. |
|---|
| 54 | start() { |
|---|
| 55 | echo -n $"Starting $prog: " |
|---|
| 56 | logger -p authpriv.info "In httpd init, running LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS" |
|---|
| 57 | ls /afs > /tmp/afs.boot |
|---|
| 58 | LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS |
|---|
| 59 | RETVAL=$? |
|---|
| 60 | echo |
|---|
| 61 | [ $RETVAL = 0 ] && touch ${lockfile} |
|---|
| 62 | logger -p authpriv.info "Ran daemon, got RETVAL=$RETVAL" |
|---|
| 63 | return $RETVAL |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | # When stopping httpd, a delay (of default 10 second) is required |
|---|
| 67 | # before SIGKILLing the httpd parent; this gives enough time for the |
|---|
| 68 | # httpd parent to SIGKILL any errant children. |
|---|
| 69 | stop() { |
|---|
| 70 | echo -n $"Stopping $prog: " |
|---|
| 71 | killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd |
|---|
| 72 | RETVAL=$? |
|---|
| 73 | echo |
|---|
| 74 | [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} |
|---|
| 75 | } |
|---|
| 76 | reload() { |
|---|
| 77 | echo -n $"Reloading $prog: " |
|---|
| 78 | if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then |
|---|
| 79 | RETVAL=6 |
|---|
| 80 | echo $"not reloading due to configuration syntax error" |
|---|
| 81 | failure $"not reloading $httpd due to configuration syntax error" |
|---|
| 82 | else |
|---|
| 83 | # Force LSB behaviour from killproc |
|---|
| 84 | LSB=1 killproc -p ${pidfile} $httpd -HUP |
|---|
| 85 | RETVAL=$? |
|---|
| 86 | if [ $RETVAL -eq 7 ]; then |
|---|
| 87 | failure $"httpd shutdown" |
|---|
| 88 | fi |
|---|
| 89 | fi |
|---|
| 90 | echo |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | # See how we were called. |
|---|
| 94 | case "$1" in |
|---|
| 95 | start) |
|---|
| 96 | start |
|---|
| 97 | ;; |
|---|
| 98 | stop) |
|---|
| 99 | stop |
|---|
| 100 | ;; |
|---|
| 101 | status) |
|---|
| 102 | status -p ${pidfile} $httpd |
|---|
| 103 | RETVAL=$? |
|---|
| 104 | ;; |
|---|
| 105 | restart) |
|---|
| 106 | stop |
|---|
| 107 | start |
|---|
| 108 | ;; |
|---|
| 109 | condrestart|try-restart) |
|---|
| 110 | if status -p ${pidfile} $httpd >&/dev/null; then |
|---|
| 111 | stop |
|---|
| 112 | start |
|---|
| 113 | fi |
|---|
| 114 | ;; |
|---|
| 115 | force-reload|reload) |
|---|
| 116 | reload |
|---|
| 117 | ;; |
|---|
| 118 | graceful|help|configtest|fullstatus) |
|---|
| 119 | $apachectl $@ |
|---|
| 120 | RETVAL=$? |
|---|
| 121 | ;; |
|---|
| 122 | *) |
|---|
| 123 | echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" |
|---|
| 124 | RETVAL=2 |
|---|
| 125 | esac |
|---|
| 126 | |
|---|
| 127 | exit $RETVAL |
|---|