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