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