]> granicus.if.org Git - apache/blob - docs/manual/stopping.xml
some language changes and fixes
[apache] / docs / manual / stopping.xml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Copyright 2002-2005 The Apache Software Foundation or its licensors, as
8  applicable.
9
10  Licensed under the Apache License, Version 2.0 (the "License");
11  you may not use this file except in compliance with the License.
12  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="stopping.xml.meta">
24
25   <title>Stopping and Restarting</title>
26
27 <summary>
28     <p>This document covers stopping and restarting Apache on
29     Unix-like systems. Windows NT, 2000 and XP users should see
30     <a href="platform/windows.html#winsvc">Running Apache as a
31     Service</a> and Windows 9x and ME users should see <a
32     href="platform/windows.html#wincons">Running Apache as a
33     Console Application</a> for information on how to control
34     Apache on those platforms.</p>
35 </summary>
36
37 <seealso><program>httpd</program></seealso>
38 <seealso><program>apachectl</program></seealso>
39
40 <section id="introduction"><title>Introduction</title>
41
42     <p>In order to stop or restart Apache, you must send a signal to
43     the running <program>httpd</program> processes.  There are two ways to
44     send the signals.  First, you can use the unix <code>kill</code>
45     command to directly send signals to the processes. You will
46     notice many <program>httpd</program> executables running on your system,
47     but you should not send signals to any of them except the parent,
48     whose pid is in the <directive
49     module="mpm_common">PidFile</directive>. That is to say you
50     shouldn't ever need to send signals to any process except the
51     parent. There are three signals that you can send the parent:
52     <code><a href="#term">TERM</a></code>,
53     <code><a href="#hup">HUP</a></code>, and
54     <code><a href="#graceful">USR1</a></code>, which
55     will be described in a moment.</p>
56
57     <p>To send a signal to the parent you should issue a command
58     such as:</p>
59
60 <example>kill -TERM `cat /usr/local/apache2/logs/httpd.pid`</example>
61
62     <p>The second method of signaling the <program>httpd</program> processes
63     is to use the <code>-k</code> command line options: <code>stop</code>,
64     <code>restart</code>, and <code>graceful</code>,
65     as described below.  These are arguments to the <program>
66     httpd</program> binary, but we recommend that
67     you send them using the <program>apachectl</program> control script, which
68     will pass them through to <program>httpd</program>.</p>
69
70     <p>After you have signaled <program>httpd</program>, you can read about
71     its progress by issuing:</p>
72
73 <example>tail -f /usr/local/apache2/logs/error_log</example>
74
75     <p>Modify those examples to match your <directive
76     module="core">ServerRoot</directive> and <directive
77     module="mpm_common">PidFile</directive> settings.</p>
78 </section>
79
80 <section id="term"><title>Stop Now</title>
81
82 <dl><dt>Signal: TERM</dt>
83 <dd><code>apachectl -k stop</code></dd>
84 </dl>
85
86     <p>Sending the <code>TERM</code> or <code>stop</code> signal to
87     the parent causes it to immediately attempt to kill off all of its
88     children. It may take it several seconds to complete killing off
89     its children.  Then the parent itself exits. Any requests in
90     progress are terminated, and no further requests are served.</p>
91 </section>
92
93 <section id="graceful"><title>Graceful Restart</title>
94
95 <dl><dt>Signal: USR1</dt>
96 <dd><code>apachectl -k graceful</code></dd>
97 </dl>
98
99     <p>The <code>USR1</code> or <code>graceful</code> signal causes
100     the parent process to <em>advise</em> the children to exit after
101     their current request (or to exit immediately if they're not
102     serving anything). The parent re-reads its configuration files and
103     re-opens its log files. As each child dies off the parent replaces
104     it with a child from the new <em>generation</em> of the
105     configuration, which begins serving new requests immediately.</p>
106
107     <note>On certain platforms that do not allow <code>USR1</code> to
108     be used for a graceful restart, an alternative signal may be used (such
109     as <code>WINCH</code>). The command <code>apachectl graceful</code>
110     will send the right signal for your platform.</note>
111
112     <p>This code is designed to always respect the process control
113     directive of the MPMs, so the number of processes and threads
114     available to serve clients will be maintained at the appropriate
115     values throughout the restart process.  Furthermore, it respects
116     <directive module="mpm_common">StartServers</directive> in the
117     following manner: if after one second at least <directive
118     module="mpm_common">StartServers</directive> new children have not
119     been created, then create enough to pick up the slack. Hence the
120     code tries to maintain both the number of children appropriate for
121     the current load on the server, and respect your wishes with the
122     <directive module="mpm_common">StartServers</directive> 
123     parameter.</p>
124
125     <p>Users of <module>mod_status</module>
126     will notice that the server statistics are <strong>not</strong>
127     set to zero when a <code>USR1</code> is sent. The code was
128     written to both minimize the time in which the server is unable
129     to serve new requests (they will be queued up by the operating
130     system, so they're not lost in any event) and to respect your
131     tuning parameters. In order to do this it has to keep the
132     <em>scoreboard</em> used to keep track of all children across
133     generations.</p>
134
135     <p>The status module will also use a <code>G</code> to indicate
136     those children which are still serving requests started before
137     the graceful restart was given.</p>
138
139     <p>At present there is no way for a log rotation script using
140     <code>USR1</code> to know for certain that all children writing
141     the pre-restart log have finished. We suggest that you use a
142     suitable delay after sending the <code>USR1</code> signal
143     before you do anything with the old log. For example if most of
144     your hits take less than 10 minutes to complete for users on
145     low bandwidth links then you could wait 15 minutes before doing
146     anything with the old log.</p>
147
148     <note>If your configuration file has errors
149     in it when you issue a restart then your parent will not
150     restart, it will exit with an error. In the case of graceful
151     restarts it will also leave children running when it exits.
152     (These are the children which are "gracefully exiting" by
153     handling their last request.) This will cause problems if you
154     attempt to restart the server -- it will not be able to bind to
155     its listening ports. Before doing a restart, you can check the
156     syntax of the configuration files with the <code>-t</code>
157     command line argument (see <program>httpd</program>). This still will not
158     guarantee that the server will restart correctly. To check the
159     semantics of the configuration files as well as the syntax, you
160     can try starting <program>httpd</program> as a non-root user. If there
161     are no errors it will attempt to open its sockets and logs and fail
162     because it's not root (or because the currently running
163     <program>httpd</program> already has those ports bound). If it fails
164     for any other reason then it's probably a config file error and the error
165     should be fixed before issuing the graceful restart.</note>
166 </section>
167
168 <section id="hup"><title>Restart Now</title>
169
170 <dl><dt>Signal: HUP</dt>
171 <dd><code>apachectl -k restart</code></dd>
172 </dl>
173
174     <p>Sending the <code>HUP</code> or <code>restart</code> signal to
175     the parent causes it to kill off its children like in
176     <code>TERM</code>, but the parent doesn't exit. It re-reads its
177     configuration files, and re-opens any log files. Then it spawns a
178     new set of children and continues serving hits.</p>
179
180     <p>Users of <module>mod_status</module>
181     will notice that the server statistics are set to zero when a
182     <code>HUP</code> is sent.</p>
183
184 <note>If your configuration file has errors in it when you issue a
185 restart then your parent will not restart, it will exit with an
186 error. See above for a method of avoiding this.</note>
187 </section>
188
189 <section id="race"><title>Appendix: signals and race conditions</title>
190
191     <p>Prior to Apache 1.2b9 there were several <em>race
192     conditions</em> involving the restart and die signals (a simply put, 
193     a race condition is a time-sensitive problem - if something happens 
194     at just the wrong time or things happen in the wrong order, 
195     undesired behaviour will result. If the same thing happens at the right 
196     time, all will be well). For those architectures that have the "right"
197     feature set we have eliminated as many as we can. But it should
198     be noted that race conditions do still exist on certain
199     architectures.</p>
200
201     <p>Architectures that use an on-disk <directive
202     module="mpm_common">ScoreBoardFile</directive> can potentially have 
203     their scoreboards corrupted. This can result in the "bind:
204     Address already in use" (after <code>HUP</code>) or "long lost
205     child came home!" (after <code>USR1</code>). The former is a fatal
206     error, while the latter just causes the server to lose a
207     scoreboard slot. So it may be advisable to use graceful
208     restarts, with an occasional hard restart. These problems are very
209     difficult to work around, but fortunately most architectures do
210     not require a scoreboard file. See the <directive
211     module="mpm_common">ScoreBoardFile</directive> documentation for
212     architecture which uses it.</p>
213
214     <p>All architectures have a small race condition in each child
215     involving the second and subsequent requests on a persistent
216     HTTP connection (KeepAlive). It may exit after reading the
217     request line but before reading any of the request headers.
218     There is a fix that was discovered too late to make 1.2. In
219     theory this isn't an issue because the KeepAlive client has to
220     expect these events because of network latencies and server
221     timeouts. In practice it doesn't seem to affect anything either
222     -- in a test case the server was restarted twenty times per
223     second and clients successfully browsed the site without
224     getting broken images or empty documents. </p>
225 </section>
226
227 </manualpage>