5088N/A<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 5088N/A <
title>Stopping and Restarting the Server</
title>
5088N/A <!-- Background white, links blue (unvisited), navy (visited), red (active) --> 5088N/A <
body bgcolor="#FFFFFF" text="#000000" link="#0000FF" 5088N/A vlink="#000080" alink="#FF0000">
5088N/A <
h1 align="CENTER">Stopping and Restarting the Server</
h1>
5088N/A <
p>This document covers stopping and restarting Apache on
5088N/A Unix-like systems. Windows users should see <
a 5503N/A <
p>You will notice many <
code>httpd</
code> executables running
5088N/A on your system, but you should not send signals to any of them
5088N/A except the parent, whose pid is in the <
a 5088N/A shouldn't ever need to send signals to any process except the
5088N/A parent. There are three signals that you can send the parent:
5088N/A <
code>TERM</
code>, <
code>HUP</
code>, and <
code>USR1</
code>,
5088N/A which will be described in a moment.</
p>
5088N/A <
p>To send a signal to the parent you should issue a command
5088N/A You can read about its progress by issuing:
5088N/A Modify those examples to match your <
a 5088N/A <
p>A shell script called <
a 5088N/A automates the processing of signalling Apache. For details
5088N/A about this script, see the documentation on <
a 5088N/A <
p><
strong>Signal:</
strong> TERM<
br />
5088N/A <
code>apachectl stop</
code></
p>
5088N/A <
p>Sending the <
code>TERM</
code> signal to the parent causes it
5088N/A to immediately attempt to kill off all of its children. It may
5088N/A take it several seconds to complete killing off its children.
5088N/A Then the parent itself exits. Any requests in progress are
5088N/A terminated, and no further requests are served.</
p>
5088N/A <
p><
strong>Signal:</
strong> USR1<
br />
5088N/A <
code>apachectl graceful</
code></
p>
5088N/A <
p>The <
code>USR1</
code> signal causes the parent process to
5088N/A <
em>advise</
em> the children to exit after their current
5088N/A request (or to exit immediately if they're not serving
5088N/A anything). The parent re-reads its configuration files and
5088N/A re-opens its log files. As each child dies off the parent
5088N/A replaces it with a child from the new <
em>generation</
em> of
5088N/A the configuration, which begins serving new requests
5088N/A <
i>On certain platforms that do not allow USR1 to be used for a
5088N/A graceful restart, an alternative signal may be used (such as
5088N/A WINCH). apachectl graceful will send the right signal for your
5088N/A <
p>This code is designed to always respect the <
a 5088N/A settings. Furthermore, it respects <
a 5088N/A following manner: if after one second at least StartServers new
5088N/A children have not been created, then create enough to pick up
5088N/A the slack. This is to say that the code tries to maintain both
5088N/A the number of children appropriate for the current load on the
5088N/A server, and respect your wishes with the StartServers
5088N/A will notice that the server statistics are <
strong>not</
strong>
5088N/A set to zero when a <
code>USR1</
code> is sent. The code was
5088N/A written to both minimize the time in which the server is unable
5088N/A to serve new requests (they will be queued up by the operating
5088N/A system, so they're not lost in any event) and to respect your
5088N/A tuning parameters. In order to do this it has to keep the
5088N/A <
em>scoreboard</
em> used to keep track of all children across
5088N/A <
p>The status module will also use a <
code>G</
code> to indicate
5088N/A those children which are still serving requests started before
5088N/A the graceful restart was given.</
p>
5088N/A <
p>At present there is no way for a log rotation script using
5088N/A <
code>USR1</
code> to know for certain that all children writing
5088N/A the pre-restart log have finished. We suggest that you use a
5088N/A suitable delay after sending the <
code>USR1</
code> signal
5088N/A before you do anything with the old log. For example if most of
5088N/A your hits take less than 10 minutes to complete for users on
5088N/A low bandwidth links then you could wait 15 minutes before doing
5088N/A anything with the old log.</
p>
5088N/A <
p><
strong>Note:</
strong> If your configuration file has errors
5088N/A in it when you issue a restart then your parent will not
5088N/A restart, it will exit with an error. In the case of graceful
5088N/A restarts it will also leave children running when it exits.
5088N/A (These are the children which are "gracefully exiting" by
5088N/A handling their last request.) This will cause problems if you
5088N/A attempt to restart the server -- it will not be able to bind to
5088N/A its listening ports. Before doing a restart, you can check the
5088N/A syntax of the configuration files with the <
code>-t</
code>
5088N/A command line argument (see <
a 5088N/A guarantee that the server will restart correctly. To check the
5088N/A semantics of the configuration files as well as the syntax, you
5088N/A can try starting httpd as a non-root user. If there are no
5088N/A errors it will attempt to open its sockets and logs and fail
5088N/A because it's not root (or because the currently running httpd
5088N/A already has those ports bound). If it fails for any other
5088N/A reason then it's probably a config file error and the error
5088N/A should be fixed before issuing the graceful restart.</
p>
5088N/A <
p><
strong>Signal:</
strong> HUP<
br />
5088N/A <
code>apachectl restart</
code></
p>
5088N/A <
p>Sending the <
code>HUP</
code> signal to the parent causes it
5088N/A to kill off its children like in <
code>TERM</
code> but the
5088N/A parent doesn't exit. It re-reads its configuration files, and
5088N/A re-opens any log files. Then it spawns a new set of children
5088N/A and continues serving hits.</
p>
5088N/A will notice that the server statistics are set to zero when a
5088N/A <
code>HUP</
code> is sent.</
p>
5088N/A <
p><
strong>Note:</
strong> If your configuration file has errors
5088N/A in it when you issue a restart then your parent will not
5088N/A restart, it will exit with an error. See below for a method of
5088N/A <
h3>Appendix: signals and race conditions</
h3>
5088N/A <
p>Prior to Apache 1.2b9 there were several <
em>race
5088N/A conditions</
em> involving the restart and die signals (a simple
5088N/A description of race condition is: a time-sensitive problem, as
5088N/A in if something happens at just the wrong time it won't behave
5088N/A as expected). For those architectures that have the "right"
5088N/A feature set we have eliminated as many as we can. But it should
5088N/A be noted that there still do exist race conditions on certain
5088N/A <
p>Architectures that use an on disk <
a 5088N/A potential to corrupt their scoreboards. This can result in the
5088N/A "bind: Address already in use" (after <
code>HUP</
code>) or
5088N/A "long lost child came home!" (after <
code>USR1</
code>). The
5088N/A former is a fatal error, while the latter just causes the
5088N/A server to lose a scoreboard slot. So it might be advisable to
5088N/A use graceful restarts, with an occasional hard restart. These
5088N/A problems are very difficult to work around, but fortunately
5088N/A most architectures do not require a scoreboard file. See the <
a 5088N/A documentation for a architecture uses it.</
p>
5088N/A <
p><
code>NEXT</
code> and <
code>MACHTEN</
code> (68k only) have
5088N/A be lost, but should not cause the server to do anything
5088N/A <!-- they don't have sigaction, or we're not using it -djg --> 5088N/A <
p>All architectures have a small race condition in each child
5088N/A involving the second and subsequent requests on a persistent
5088N/A HTTP connection (KeepAlive). It may exit after reading the
5088N/A request line but before reading any of the request headers.
5088N/A There is a fix that was discovered too late to make 1.2. In
5088N/A theory this isn't an issue because the KeepAlive client has to
5088N/A expect these events because of network latencies and server
5088N/A timeouts. In practice it doesn't seem to affect anything either
5088N/A -- in a test case the server was restarted twenty times per
5088N/A second and clients successfully browsed the site without
5088N/A getting broken images or empty documents.