]> granicus.if.org Git - apache/blob - docs/manual/stopping.html
Document the problem of config file errors.
[apache] / docs / manual / stopping.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Stopping and Restarting Apache</TITLE>
5 </HEAD>
6
7 <BODY>
8 <!--#include virtual="header.html" -->
9 <h1>Stopping and Restarting Apache</h1>
10
11 <p>You will notice many <code>httpd</code> executables running on your system,
12 but you should not send signals to any of them except the parent, whose
13 pid is in the <a href="mod/core.html#pidfile">PidFile</a>.  That is to
14 say you shouldn't ever need to send signals to any process except the
15 parent.  There are three signals that you can send the parent:
16 <code>TERM</code>, <code>HUP</code>, and <code>USR1</code>, which will
17 be described in a moment.
18
19 <p>To send a signal to the parent you should issue a command such as:
20 <blockquote><pre>
21     kill -TERM `cat /usr/local/etc/httpd/logs/httpd.pid`
22 </pre></blockquote>
23
24 You can read about its progress by issuing:
25
26 <blockquote><pre>
27     tail -f /usr/local/etc/httpd/logs/error_log
28 </pre></blockquote>
29
30 Modify those examples to match your
31 <a href="mod/core.html#serverroot">ServerRoot</a> and
32 <a href="mod/core.html#pidfile">PidFile</a> settings.
33
34 <h3>TERM Signal: stop now</h3>
35
36 <p>Sending the <code>TERM</code> signal to the parent causes it to
37 immediately attempt to kill off all of its children.  It may take it
38 several seconds to complete killing off its children.  Then the
39 parent itself exits.  Any requests in progress are terminated, and no
40 further requests are served.
41
42 <h3>HUP Signal: restart now</h3>
43
44 <p>Sending the <code>HUP</code> signal to the parent causes it to kill off
45 its children like in <code>TERM</code> but the parent doesn't exit.  It
46 re-reads its configuration files, and re-opens any log files.
47 Then it spawns a new set of children and continues
48 serving hits.
49
50 <p>Users of the
51 <a href="mod/mod_status.html">status module</a>
52 will notice that the server statistics are
53 set to zero when a <code>HUP</code> is sent.
54
55 <p><b>Note:</b> If your configuration file has errors in it when you issue a
56 restart then your parent will not restart, it will exit with an error.
57 See below for a method of avoiding this.
58
59 <h3>USR1 Signal: graceful restart</h3>
60
61 <p><b>Note:</b> prior to release 1.2b9 this code is quite unstable and
62 shouldn't be used at all.
63
64 <p>The <code>USR1</code> signal causes the parent process to <i>advise</i>
65 the children to exit after their current request (or to exit immediately
66 if they're not serving anything).  The parent re-reads its configuration
67 files and re-opens its log files.  As each child dies off the parent
68 replaces it with a child from the new <i>generation</i> of the
69 configuration, which begins serving new requests immediately.
70
71 <p>This code is designed to always respect the
72 <a href="mod/core.html#maxclients">MaxClients</a>,
73 <a href="mod/core.html#minspareservers">MinSpareServers</a>,
74 and <a href="mod/core.html#maxspareservers">MaxSpareServers</a> settings.
75 Furthermore, it respects <a href="mod/core.html#startservers">StartServers</a>
76 in the following manner:  if after one second at least StartServers new
77 children have not been created, then create enough to pick up the slack.
78 This is to say that the code tries to maintain both the number of children
79 appropriate for the current load on the server, and respect your wishes
80 with the StartServers parameter.
81
82 <p>Users of the
83 <a href="mod/mod_status.html">status module</a>
84 will notice that the server statistics
85 are <b>not</b> set to zero when a <code>USR1</code> is sent.  The code
86 was written to both minimize the time in which the server is unable to serve
87 new requests (they will be queued up by the operating system, so they're
88 not lost in any event) and to respect your tuning parameters.  In order
89 to do this it has to keep the <i>scoreboard</i> used to keep track
90 of all children across generations.
91
92 <p>The status module will also use a <code>G</code> to indicate those
93 children which are still serving requests started before the graceful
94 restart was given.
95
96 <p>At present there is no way for a log rotation script using
97 <code>USR1</code> to know for certain that all children writing the
98 pre-restart log have finished.  We suggest that you use a suitable delay
99 after sending the <code>USR1</code> signal before you do anything with the
100 old log.  For example if most of your hits take less than 10 minutes to
101 complete for users on low bandwidth links then you could wait 15 minutes
102 before doing anything with the old log.
103
104 <p><b>Note:</b> If your configuration file has errors in it when you issue a
105 restart then your parent will not restart, it will exit with an error.
106 In the case of graceful
107 restarts it will also leave children running when it exits.  (These are
108 the children which are "gracefully exiting" by handling their last request.)
109 This will cause problems if you attempt to restart the server -- it will
110 not be able to bind to its listening ports.  At present the only work
111 around is to check the syntax of your files before doing a restart.  The
112 easiest way is to just run httpd as a non-root user.  If there are no
113 errors it will attempt to open its sockets and logs and fail because it's
114 not root (or because the currently running httpd already has those ports
115 bound).  If it fails for any other reason then it's probably a config file
116 error and the error should be fixed before issuing the graceful restart.
117
118 <h3>Appendix: signals and race conditions</h3>
119
120 <p>Prior to Apache 1.2b9 there were several <i>race conditions</i>
121 involving the restart and die signals (a simple description of race
122 condition is: a time-sensitive problem, as in if something happens at just
123 the wrong time it won't behave as expected).  For those architectures that
124 have the "right" feature set we have eliminated as many as we can.
125 But it should be noted that there still do exist race conditions on
126 certain architectures.
127
128 <p>Architectures that use an on disk
129 <a href="mod/core.html#scoreboardfile">ScoreBoardFile</a>
130 have the potential to corrupt their scoreboards.  This can result in
131 the "bind: Address already in use" (after <code>HUP</code>) or
132 "long lost child came home!" (after <code>USR1</code>).  The former is
133 a fatal error, while the latter just causes the server to lose a scoreboard
134 slot.  So it might be advisable to use graceful restarts, with
135 an occasional hard restart.  These problems are very difficult to work
136 around, but fortunately most architectures do not require a scoreboard file.
137 See the ScoreBoardFile documentation for a method to determine if your
138 architecture uses it.
139
140 <p><code>NEXT</code> and <code>MACHTEN</code> have small race conditions
141 which can cause a restart/die signal to be lost, but should not cause the
142 server to do anything otherwise problematic.
143 <!-- they don't have sigaction, or we're not using it -djg -->
144
145 <p>All architectures have a small race condition in each child involving
146 the second and subsequent requests on a persistent HTTP connection
147 (KeepAlive).  It may exit after reading the request line but before
148 reading any of the request headers.  There is a fix that was discovered
149 too late to make 1.2.  In theory this isn't an issue because the KeepAlive
150 client has to expect these events because of network latencies and
151 server timeouts.  In practice it doesn't seem to affect anything either
152 -- in a test case the server was restarted twenty times per second and
153 clients successfully browsed the site without getting broken images or
154 empty documents.
155
156 <!--#include virtual="footer.html" -->
157 </BODY>
158 </HTML>