stopping.html revision 6da353b1fd3b5e77b8c7b5cbffd8beb61e68e917
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<TITLE>Stopping and Restarting Apache</TITLE>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat BGCOLOR="#FFFFFF"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat TEXT="#000000"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat LINK="#0000FF"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat VLINK="#000080"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat ALINK="#FF0000"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<!--#include virtual="header.html" -->
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<h1 ALIGN="CENTER">Stopping and Restarting Apache</h1>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>You will notice many <code>httpd</code> executables running on your system,
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatbut you should not send signals to any of them except the parent, whose
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatpid is in the <a href="mod/core.html#pidfile">PidFile</a>. That is to
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatsay you shouldn't ever need to send signals to any process except the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatparent. There are three signals that you can send the parent:
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<code>TERM</code>, <code>HUP</code>, and <code>USR1</code>, which will
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatbe described in a moment.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>To send a signal to the parent you should issue a command such as:
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat kill -TERM `cat /usr/local/apache/logs/httpd.pid`
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatYou can read about its progress by issuing:
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatModify those examples to match your
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/core.html#serverroot">ServerRoot</a> and
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/core.html#pidfile">PidFile</a> settings.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>Sending the <code>TERM</code> signal to the parent causes it to
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatimmediately attempt to kill off all of its children. It may take it
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatseveral seconds to complete killing off its children. Then the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatparent itself exits. Any requests in progress are terminated, and no
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfurther requests are served.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>Sending the <code>HUP</code> signal to the parent causes it to kill off
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatits children like in <code>TERM</code> but the parent doesn't exit. It
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatre-reads its configuration files, and re-opens any log files.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatThen it spawns a new set of children and continues
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>Users of the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/mod_status.html">status module</a>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwill notice that the server statistics are
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p><b>Note:</b> If your configuration file has errors in it when you issue a
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatrestart then your parent will not restart, it will exit with an error.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatSee below for a method of avoiding this.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p><b>Note:</b> prior to release 1.2b9 this code is quite unstable and
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatshouldn't be used at all.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>The <code>USR1</code> signal causes the parent process to <i>advise</i>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatthe children to exit after their current request (or to exit immediately
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif they're not serving anything). The parent re-reads its configuration
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfiles and re-opens its log files. As each child dies off the parent
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatreplaces it with a child from the new <i>generation</i> of the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatconfiguration, which begins serving new requests immediately.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>This code is designed to always respect the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/core.html#maxclients">MaxClients</a>,
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/core.html#minspareservers">MinSpareServers</a>,
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatand <a href="mod/core.html#maxspareservers">MaxSpareServers</a> settings.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatFurthermore, it respects <a href="mod/core.html#startservers">StartServers</a>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatin the following manner: if after one second at least StartServers new
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatchildren have not been created, then create enough to pick up the slack.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatThis is to say that the code tries to maintain both the number of children
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatappropriate for the current load on the server, and respect your wishes
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwith the StartServers parameter.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>Users of the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<a href="mod/mod_status.html">status module</a>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwill notice that the server statistics
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatare <b>not</b> set to zero when a <code>USR1</code> is sent. The code
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwas written to both minimize the time in which the server is unable to serve
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatnew requests (they will be queued up by the operating system, so they're
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatnot lost in any event) and to respect your tuning parameters. In order
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatto do this it has to keep the <i>scoreboard</i> used to keep track
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatof all children across generations.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>The status module will also use a <code>G</code> to indicate those
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatchildren which are still serving requests started before the graceful
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatrestart was given.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>At present there is no way for a log rotation script using
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<code>USR1</code> to know for certain that all children writing the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatpre-restart log have finished. We suggest that you use a suitable delay
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatafter sending the <code>USR1</code> signal before you do anything with the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatold log. For example if most of your hits take less than 10 minutes to
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcomplete for users on low bandwidth links then you could wait 15 minutes
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatbefore doing anything with the old log.
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<p><b>Note:</b> If your configuration file has errors in it when you issue a
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatrestart then your parent will not restart, it will exit with an error.
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatIn the case of graceful
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatrestarts it will also leave children running when it exits. (These are
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatthe children which are "gracefully exiting" by handling their last request.)
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatThis will cause problems if you attempt to restart the server -- it will
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatnot be able to bind to its listening ports. At present the only work
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozataround is to check the syntax of your files before doing a restart. The
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozateasiest way is to just run httpd as a non-root user. If there are no
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozaterrors it will attempt to open its sockets and logs and fail because it's
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatnot root (or because the currently running httpd already has those ports
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatbound). If it fails for any other reason then it's probably a config file
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozaterror and the error should be fixed before issuing the graceful restart.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<h3>Appendix: signals and race conditions</h3>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p>Prior to Apache 1.2b9 there were several <i>race conditions</i>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatinvolving the restart and die signals (a simple description of race
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcondition is: a time-sensitive problem, as in if something happens at just
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatthe wrong time it won't behave as expected). For those architectures that
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozathave the "right" feature set we have eliminated as many as we can.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatBut it should be noted that there still do exist race conditions on
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcertain architectures.
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<p>Architectures that use an on disk
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<a href="mod/core.html#scoreboardfile">ScoreBoardFile</a>
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozathave the potential to corrupt their scoreboards. This can result in
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatthe "bind: Address already in use" (after <code>HUP</code>) or
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat"long lost child came home!" (after <code>USR1</code>). The former is
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozata fatal error, while the latter just causes the server to lose a scoreboard
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatslot. So it might be advisable to use graceful restarts, with
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatan occasional hard restart. These problems are very difficult to work
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozataround, but fortunately most architectures do not require a scoreboard file.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatSee the ScoreBoardFile documentation for a method to determine if your
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatarchitecture uses it.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat<p><code>NEXT</code> and <code>MACHTEN</code> (68k only) have small race
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwhich can cause a restart/die signal to be lost, but should not cause the
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatserver to do anything otherwise problematic.
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<!-- they don't have sigaction, or we're not using it -djg -->
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<p>All architectures have a small race condition in each child involving
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatthe second and subsequent requests on a persistent HTTP connection
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat(KeepAlive). It may exit after reading the request line but before
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatreading any of the request headers. There is a fix that was discovered
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozattoo late to make 1.2. In theory this isn't an issue because the KeepAlive
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatclient has to expect these events because of network latencies and
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatserver timeouts. In practice it doesn't seem to affect anything either
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat-- in a test case the server was restarted twenty times per second and
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatclients successfully browsed the site without getting broken images or
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatempty documents.
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat<!--#include virtual="footer.html" -->