]> granicus.if.org Git - apache/blob - support/apachectl.in
Remove hardcoded paths from MPMs and move them to a more central
[apache] / support / apachectl.in
1 #!/bin/sh
2 #
3 # Copyright (c) 2000-2002 The Apache Software Foundation.
4 # See license at the end of this file.
5 #
6 # Apache control script designed to allow an easy command line interface
7 # to controlling Apache.  Written by Marc Slemko, 1997/08/23
8
9 # The exit codes returned are:
10 #       0 - operation completed successfully
11 #       1 - 
12 #       2 - usage error
13 #       3 - httpd could not be started
14 #       4 - httpd could not be stopped
15 #       5 - httpd could not be started during a restart
16 #       6 - httpd could not be restarted during a restart
17 #       7 - httpd could not be restarted during a graceful restart
18 #       8 - configuration syntax error
19 #
20 # When multiple arguments are given, only the error from the _last_
21 # one is reported.  Run "apachectl help" for usage info
22 #
23 ARGV="$@"
24 #
25 # |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
26 # --------------------                              --------------------
27
28 # the path to your PID file
29 PIDFILE=@exp_runtimedir@/@progname@.pid
30 #
31 # the path to your httpd binary, including options if necessary
32 HTTPD='@exp_bindir@/@progname@'
33 #
34 # pick up any necessary environment variables
35 if test -f @exp_bindir@/envvars; then
36   . @exp_bindir@/envvars
37 fi
38 #
39 # a command that outputs a formatted text version of the HTML at the
40 # url given on the command line.  Designed for lynx, however other
41 # programs may work.  
42 LYNX="lynx -dump"
43 #
44 # the URL to your server's mod_status status page.  If you do not
45 # have one, then status and fullstatus will not work.
46 STATUSURL="http://localhost:@PORT@/server-status"
47 #
48 # --------------------                              --------------------
49 # ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||
50
51 ERROR=0
52 if [ "x$ARGV" = "x" ] ; then 
53     ARGS="help"
54 fi
55
56 for ARG in $ARGV $ARGS
57 do
58     # check for pidfile
59     if [ -f $PIDFILE ] ; then
60         PID=`cat $PIDFILE`
61         if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
62             STATUS="@progname@ (pid $PID) running"
63             RUNNING=1
64         else
65             STATUS="@progname@ (pid $PID?) not running"
66             RUNNING=0
67         fi
68     else
69         STATUS="@progname@ (no pid file) not running"
70         RUNNING=0
71     fi
72
73     case $ARG in
74     start)
75         if [ $RUNNING -eq 1 ]; then
76             echo "$0 $ARG: @progname@ (pid $PID) already running"
77             continue
78         fi
79         if $HTTPD ; then
80             echo "$0 $ARG: @progname@ started"
81         else
82             echo "$0 $ARG: @progname@ could not be started"
83             ERROR=3
84         fi
85         ;;
86     startssl|sslstart|start-SSL)
87         if [ $RUNNING -eq 1 ]; then
88             echo "$0 $ARG: @progname@ (pid $PID) already running"
89             continue
90         fi
91         if $HTTPD -DSSL; then
92             echo "$0 $ARG: @progname@ started"
93         else
94             echo "$0 $ARG: @progname@ could not be started"
95             ERROR=3
96         fi
97         ;;
98     stop)
99         if [ $RUNNING -eq 0 ]; then
100             echo "$0 $ARG: $STATUS"
101             continue
102         fi
103         if kill $PID ; then
104             echo "$0 $ARG: @progname@ stopped"
105         else
106             echo "$0 $ARG: @progname@ could not be stopped"
107             ERROR=4
108         fi
109         ;;
110     restart)
111         if [ $RUNNING -eq 0 ]; then
112             echo "$0 $ARG: @progname@ not running, trying to start"
113             if $HTTPD ; then
114                 echo "$0 $ARG: @progname@ started"
115             else
116                 echo "$0 $ARG: @progname@ could not be started"
117                 ERROR=5
118             fi
119         else
120             if $HTTPD -t >/dev/null 2>&1; then
121                 if kill -HUP $PID ; then
122                     echo "$0 $ARG: @progname@ restarted"
123                 else
124                     echo "$0 $ARG: @progname@ could not be restarted"
125                     ERROR=6
126                 fi
127             else
128                 echo "$0 $ARG: configuration broken, ignoring restart"
129                 echo "$0 $ARG: (run 'apachectl configtest' for details)"
130                 ERROR=6
131             fi
132         fi
133         ;;
134     graceful)
135         if [ $RUNNING -eq 0 ]; then
136             echo "$0 $ARG: @progname@ not running, trying to start"
137             if $HTTPD ; then
138                 echo "$0 $ARG: @progname@ started"
139             else
140                 echo "$0 $ARG: @progname@ could not be started"
141                 ERROR=5
142             fi
143         else
144             if $HTTPD -t >/dev/null 2>&1; then
145                 if kill -@AP_SIG_GRACEFUL_SHORT@ $PID ; then
146                     echo "$0 $ARG: @progname@ gracefully restarted"
147                 else
148                     echo "$0 $ARG: @progname@ could not be restarted"
149                     ERROR=7
150                 fi
151             else
152                 echo "$0 $ARG: configuration broken, ignoring restart"
153                 echo "$0 $ARG: (run 'apachectl configtest' for details)"
154                 ERROR=7
155             fi
156         fi
157         ;;
158     status)
159         $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
160         ;;
161     fullstatus)
162         $LYNX $STATUSURL
163         ;;
164     configtest)
165         if $HTTPD -t; then
166             :
167         else
168             ERROR=8
169         fi
170         ;;
171     *)
172         echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
173         cat <<EOF
174
175 start      - start @progname@
176 startssl   - start @progname@ with SSL enabled
177 stop       - stop @progname@
178 restart    - restart @progname@ if running by sending a SIGHUP or start if 
179              not running
180 fullstatus - dump a full status screen; requires lynx and mod_status enabled
181 status     - dump a short status screen; requires lynx and mod_status enabled
182 graceful   - do a graceful restart by sending a @AP_SIG_GRACEFUL@ or start if not running
183 configtest - do a configuration syntax test
184 help       - this screen
185
186 EOF
187         ERROR=2
188     ;;
189
190     esac
191
192 done
193
194 exit $ERROR
195
196 # ====================================================================
197 # The Apache Software License, Version 1.1
198 #
199 # Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
200 # reserved.
201 #
202 # Redistribution and use in source and binary forms, with or without
203 # modification, are permitted provided that the following conditions
204 # are met:
205 #
206 # 1. Redistributions of source code must retain the above copyright
207 #    notice, this list of conditions and the following disclaimer.
208 #
209 # 2. Redistributions in binary form must reproduce the above copyright
210 #    notice, this list of conditions and the following disclaimer in
211 #    the documentation and/or other materials provided with the
212 #    distribution.
213 #
214 # 3. The end-user documentation included with the redistribution,
215 #    if any, must include the following acknowledgment:
216 #       "This product includes software developed by the
217 #        Apache Software Foundation (http://www.apache.org/)."
218 #    Alternately, this acknowledgment may appear in the software itself,
219 #    if and wherever such third-party acknowledgments normally appear.
220 #
221 # 4. The names "Apache" and "Apache Software Foundation" must
222 #    not be used to endorse or promote products derived from this
223 #    software without prior written permission. For written
224 #    permission, please contact apache@apache.org.
225 #
226 # 5. Products derived from this software may not be called "Apache",
227 #    nor may "Apache" appear in their name, without prior written
228 #    permission of the Apache Software Foundation.
229 #
230 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
231 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
232 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
233 # DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
234 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
237 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
238 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
239 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
240 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241 # SUCH DAMAGE.
242 # ====================================================================
243 #
244 # This software consists of voluntary contributions made by many
245 # individuals on behalf of the Apache Software Foundation.  For more
246 # information on the Apache Software Foundation, please see
247 # <http://www.apache.org/>.
248 #
249 # Portions of this software are based upon public domain software
250 # originally written at the National Center for Supercomputing Applications,
251 # University of Illinois, Urbana-Champaign.
252 #