1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>Stopping and Restarting - Apache HTTP Server</title>
9 <link href="./style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="./style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="./style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.0</p>
16 <img alt="" src="./images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="<-" alt="<-" src="./images/left.gif" /></a></div>
19 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.0</a></div><div id="page-content"><div id="preamble"><h1>Stopping and Restarting</h1>
21 <p><span>Available Languages: </span><a href="./de/stopping.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> |
22 <a href="./en/stopping.html" title="English"> en </a> |
23 <a href="./es/stopping.html" hreflang="es" rel="alternate" title="Español"> es </a> |
24 <a href="./ja/stopping.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
25 <a href="./ko/stopping.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
26 <a href="./ru/stopping.html" hreflang="ru" rel="alternate" title="Russian"> ru </a> |
27 <a href="./tr/stopping.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
30 <p>This document covers stopping and restarting Apache on
31 Unix-like systems. Windows NT, 2000 and XP users should see
32 <a href="platform/windows.html#winsvc">Running Apache as a
33 Service</a> and Windows 9x and ME users should see <a href="platform/windows.html#wincons">Running Apache as a
34 Console Application</a> for information on how to control
35 Apache on those platforms.</p>
37 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#introduction">Introduction</a></li>
38 <li><img alt="" src="./images/down.gif" /> <a href="#term">Stop Now</a></li>
39 <li><img alt="" src="./images/down.gif" /> <a href="#graceful">Graceful Restart</a></li>
40 <li><img alt="" src="./images/down.gif" /> <a href="#hup">Restart Now</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#race">Appendix: signals and race conditions</a></li>
42 </ul><h3>See also</h3><ul class="seealso"><li><code class="program"><a href="./programs/httpd.html">httpd</a></code></li><li><code class="program"><a href="./programs/apachectl.html">apachectl</a></code></li><li><a href="invoking.html">Starting</a></li></ul></div>
43 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
45 <h2><a name="introduction" id="introduction">Introduction</a></h2>
47 <p>In order to stop or restart Apache, you must send a signal to
48 the running <code class="program"><a href="./programs/httpd.html">httpd</a></code> processes. There are two ways to
49 send the signals. First, you can use the unix <code>kill</code>
50 command to directly send signals to the processes. You will
51 notice many <code class="program"><a href="./programs/httpd.html">httpd</a></code> executables running on your system,
52 but you should not send signals to any of them except the parent,
53 whose pid is in the <code class="directive"><a href="./mod/mpm_common.html#pidfile">PidFile</a></code>. That is to say you
54 shouldn't ever need to send signals to any process except the
55 parent. There are three signals that you can send the parent:
56 <code><a href="#term">TERM</a></code>,
57 <code><a href="#hup">HUP</a></code>, and
58 <code><a href="#graceful">USR1</a></code>, which
59 will be described in a moment.</p>
61 <p>To send a signal to the parent you should issue a command
64 <div class="example"><p><code>kill -TERM `cat /usr/local/apache2/logs/httpd.pid`</code></p></div>
66 <p>The second method of signaling the <code class="program"><a href="./programs/httpd.html">httpd</a></code> processes
67 is to use the <code>-k</code> command line options: <code>stop</code>,
68 <code>restart</code>, and <code>graceful</code>,
69 as described below. These are arguments to the <code class="program"><a href="./programs/httpd.html">httpd</a></code> binary, but we recommend that
70 you send them using the <code class="program"><a href="./programs/apachectl.html">apachectl</a></code> control script, which
71 will pass them through to <code class="program"><a href="./programs/httpd.html">httpd</a></code>.</p>
73 <p>After you have signaled <code class="program"><a href="./programs/httpd.html">httpd</a></code>, you can read about
74 its progress by issuing:</p>
76 <div class="example"><p><code>tail -f /usr/local/apache2/logs/error_log</code></p></div>
78 <p>Modify those examples to match your <code class="directive"><a href="./mod/core.html#serverroot">ServerRoot</a></code> and <code class="directive"><a href="./mod/mpm_common.html#pidfile">PidFile</a></code> settings.</p>
79 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
81 <h2><a name="term" id="term">Stop Now</a></h2>
83 <dl><dt>Signal: TERM</dt>
84 <dd><code>apachectl -k stop</code></dd>
87 <p>Sending the <code>TERM</code> or <code>stop</code> signal to
88 the parent causes it to immediately attempt to kill off all of its
89 children. It may take it several seconds to complete killing off
90 its children. Then the parent itself exits. Any requests in
91 progress are terminated, and no further requests are served.</p>
92 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
94 <h2><a name="graceful" id="graceful">Graceful Restart</a></h2>
96 <dl><dt>Signal: USR1</dt>
97 <dd><code>apachectl -k graceful</code></dd>
100 <p>The <code>USR1</code> or <code>graceful</code> signal causes
101 the parent process to <em>advise</em> the children to exit after
102 their current request (or to exit immediately if they're not
103 serving anything). The parent re-reads its configuration files and
104 re-opens its log files. As each child dies off the parent replaces
105 it with a child from the new <em>generation</em> of the
106 configuration, which begins serving new requests immediately.</p>
108 <div class="note">On certain platforms that do not allow <code>USR1</code> to
109 be used for a graceful restart, an alternative signal may be used (such
110 as <code>WINCH</code>). The command <code>apachectl graceful</code>
111 will send the right signal for your platform.</div>
113 <p>This code is designed to always respect the process control
114 directive of the MPMs, so the number of processes and threads
115 available to serve clients will be maintained at the appropriate
116 values throughout the restart process. Furthermore, it respects
117 <code class="directive"><a href="./mod/mpm_common.html#startservers">StartServers</a></code> in the
118 following manner: if after one second at least <code class="directive"><a href="./mod/mpm_common.html#startservers">StartServers</a></code> 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 <code class="directive"><a href="./mod/mpm_common.html#startservers">StartServers</a></code>
125 <p>Users of <code class="module"><a href="./mod/mod_status.html">mod_status</a></code>
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
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>
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>
148 <div class="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 <code class="program"><a href="./programs/httpd.html">httpd</a></code>). 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 <code class="program"><a href="./programs/httpd.html">httpd</a></code> 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 <code class="program"><a href="./programs/httpd.html">httpd</a></code> 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.</div>
166 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
167 <div class="section">
168 <h2><a name="hup" id="hup">Restart Now</a></h2>
170 <dl><dt>Signal: HUP</dt>
171 <dd><code>apachectl -k restart</code></dd>
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>
180 <p>Users of <code class="module"><a href="./mod/mod_status.html">mod_status</a></code>
181 will notice that the server statistics are set to zero when a
182 <code>HUP</code> is sent.</p>
184 <div class="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.</div>
187 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
188 <div class="section">
189 <h2><a name="race" id="race">Appendix: signals and race conditions</a></h2>
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
201 <p>Architectures that use an on-disk <code class="directive"><a href="./mod/mpm_common.html#scoreboardfile">ScoreBoardFile</a></code> can potentially have
202 their scoreboards corrupted. This can result in the "bind:
203 Address already in use" (after <code>HUP</code>) or "long lost
204 child came home!" (after <code>USR1</code>). The former is a fatal
205 error, while the latter just causes the server to lose a
206 scoreboard slot. So it may be advisable to use graceful
207 restarts, with an occasional hard restart. These problems are very
208 difficult to work around, but fortunately most architectures do
209 not require a scoreboard file. See the <code class="directive"><a href="./mod/mpm_common.html#scoreboardfile">ScoreBoardFile</a></code> documentation for
210 architecture which uses it.</p>
212 <p>All architectures have a small race condition in each child
213 involving the second and subsequent requests on a persistent
214 HTTP connection (KeepAlive). It may exit after reading the
215 request line but before reading any of the request headers.
216 There is a fix that was discovered too late to make 1.2. In
217 theory this isn't an issue because the KeepAlive client has to
218 expect these events because of network latencies and server
219 timeouts. In practice it doesn't seem to affect anything either
220 -- in a test case the server was restarted twenty times per
221 second and clients successfully browsed the site without
222 getting broken images or empty documents. </p>
224 <div class="bottomlang">
225 <p><span>Available Languages: </span><a href="./de/stopping.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> |
226 <a href="./en/stopping.html" title="English"> en </a> |
227 <a href="./es/stopping.html" hreflang="es" rel="alternate" title="Español"> es </a> |
228 <a href="./ja/stopping.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
229 <a href="./ko/stopping.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
230 <a href="./ru/stopping.html" hreflang="ru" rel="alternate" title="Russian"> ru </a> |
231 <a href="./tr/stopping.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
232 </div><div id="footer">
233 <p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
234 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div>