1#!/bin/bash
2#
3# Licensed to the Apache Software Foundation (ASF) under one or more
4# contributor license agreements.  See the NOTICE file distributed with
5# this work for additional information regarding copyright ownership.
6# The ASF licenses this file to You under the Apache License, Version 2.0
7# (the "License"); you may not use this file except in compliance with
8# the License.  You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18#
19# httpd        Startup script for the Apache Web Server
20#
21# chkconfig: - 85 15
22# description: The Apache HTTP Server is an efficient and extensible  \
23#             server implementing the current HTTP standards.
24# processname: httpd
25# pidfile: /var/run/httpd.pid
26# config: /etc/sysconfig/httpd
27#
28### BEGIN INIT INFO
29# Provides: httpd
30# Required-Start: $local_fs $remote_fs $network $named
31# Required-Stop: $local_fs $remote_fs $network
32# Should-Start: distcache
33# Short-Description: start and stop Apache HTTP Server
34# Description: The Apache HTTP Server is an extensible server 
35#  implementing the current HTTP standards.
36### END INIT INFO
37
38# Source function library.
39. /etc/rc.d/init.d/functions
40
41# What were we called? Multiple instances of the same daemon can be
42# created by creating suitably named symlinks to this startup script
43prog=$(basename $0 | sed -e 's/^[SK][0-9][0-9]//')
44
45if [ -f /etc/sysconfig/${prog} ]; then
46        . /etc/sysconfig/${prog}
47fi
48
49# Start httpd in the C locale by default.
50HTTPD_LANG=${HTTPD_LANG-"C"}
51
52# This will prevent initlog from swallowing up a pass-phrase prompt if
53# mod_ssl needs a pass-phrase from the user.
54INITLOG_ARGS=""
55
56# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
57# with the thread-based "worker" MPM; BE WARNED that some modules may not
58# work correctly with a thread-based MPM; notably PHP will refuse to start.
59
60httpd=${HTTPD-/usr/sbin/httpd}
61pidfile=${PIDFILE-/var/run/${prog}.pid}
62lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
63RETVAL=0
64
65# check for 1.3 configuration
66check13 () {
67	CONFFILE=/etc/httpd/conf/httpd.conf
68	GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
69	GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
70	GONE="${GONE}AccessConfig|ResourceConfig)"
71	if grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
72		echo
73		echo 1>&2 " Apache 1.3 configuration directives found"
74		echo 1>&2 " please read @docdir@/migration.html"
75		failure "Apache 1.3 config directives test"
76		echo
77		exit 1
78	fi
79}
80
81# The semantics of these two functions differ from the way apachectl does
82# things -- attempting to start while running is a failure, and shutdown
83# when not running is also a failure.  So we just do it the way init scripts
84# are expected to behave here.
85start() {
86        echo -n $"Starting $prog: "
87        check13 || exit 1
88        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
89        RETVAL=$?
90        echo
91        [ $RETVAL = 0 ] && touch ${lockfile}
92        return $RETVAL
93}
94stop() {
95	echo -n $"Stopping $prog: "
96	killproc -p ${pidfile} -d 10 $httpd
97	RETVAL=$?
98	echo
99	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
100}
101reload() {
102	echo -n $"Reloading $prog: "
103	check13 || exit 1
104	killproc -p ${pidfile} $httpd -HUP
105	RETVAL=$?
106	echo
107}
108
109# See how we were called.
110case "$1" in
111  start)
112	start
113	;;
114  stop)
115	stop
116	;;
117  status)
118        if ! test -f ${pidfile}; then
119            echo $prog is stopped
120            RETVAL=3
121        else  
122            status -p ${pidfile} $httpd
123            RETVAL=$?
124        fi
125        ;;
126  restart)
127	stop
128	start
129	;;
130  condrestart)
131	if test -f ${pidfile} && status -p ${pidfile} $httpd >&/dev/null; then
132		stop
133		start
134	fi
135	;;
136  reload)
137        reload
138	;;
139  configtest)
140        LANG=$HTTPD_LANG $httpd $OPTIONS -t
141        RETVAL=$?
142        ;;
143  graceful)
144        echo -n $"Gracefully restarting $prog: "
145        LANG=$HTTPD_LANG $httpd $OPTIONS -k $@
146        RETVAL=$?
147        echo
148        ;;
149  *)
150	echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|graceful|help|configtest}"
151	exit 1
152esac
153
154exit $RETVAL
155
156