stopping.html revision 091caae3b2ebdb760c98575d0d5e349cd686f913
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<HTML>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<HEAD>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<TITLE>Stopping and Restarting Apache</TITLE>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync</HEAD>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
c58f1213e628a545081c70e26c6b67a841cff880vboxsync<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<BODY
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync BGCOLOR="#FFFFFF"
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync TEXT="#000000"
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync LINK="#0000FF"
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync VLINK="#000080"
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync ALINK="#FF0000"
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<!--#include virtual="header.html" -->
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<H1 ALIGN="CENTER">Stopping and Restarting Apache</H1>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>You will notice many <CODE>httpd</CODE> executables running on your system,
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncbut you should not send signals to any of them except the parent, whose
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncpid is in the <A HREF="mod/core.html#pidfile">PidFile</A>. That is to
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncsay you shouldn't ever need to send signals to any process except the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncparent. There are three signals that you can send the parent:
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<CODE>TERM</CODE>, <CODE>HUP</CODE>, and <CODE>USR1</CODE>, which will
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncbe described in a moment.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>To send a signal to the parent you should issue a command such as:
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<BLOCKQUOTE><PRE>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync kill -TERM `cat /usr/local/apache/logs/httpd.pid`
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync</PRE></BLOCKQUOTE>
7413b370d1af0fbac98c8ba74551c32e715b3af7vboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncYou can read about its progress by issuing:
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
e07acfb7f2dbb8bb40804024c79fd3139bdb3f24vboxsync<BLOCKQUOTE><PRE>
e07acfb7f2dbb8bb40804024c79fd3139bdb3f24vboxsync tail -f /usr/local/apache/logs/error_log
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync</PRE></BLOCKQUOTE>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncModify those examples to match your
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<A HREF="mod/core.html#serverroot">ServerRoot</A> and
c7a378ed2fbad681c0b674351d698ef20a368935vboxsync<A HREF="mod/core.html#pidfile">PidFile</A> settings.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>As of Apache 1.3 we provide a script <CODE>src/support/apachectl</CODE>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncwhich can be used to start, stop, and restart Apache. It may need a
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsynclittle customization for your system, see the comments at the top of
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncthe script.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<H3>TERM Signal: stop now</H3>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>Sending the <CODE>TERM</CODE> signal to the parent causes it to
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncimmediately attempt to kill off all of its children. It may take it
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncseveral seconds to complete killing off its children. Then the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncparent itself exits. Any requests in progress are terminated, and no
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncfurther requests are served.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<H3>HUP Signal: restart now</H3>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>Sending the <CODE>HUP</CODE> signal to the parent causes it to kill off
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncits children like in <CODE>TERM</CODE> but the parent doesn't exit. It
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncre-reads its configuration files, and re-opens any log files.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncThen it spawns a new set of children and continues
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncserving hits.
941fd57f76689448d94928ce657a521e215f8671vboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>Users of the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<A HREF="mod/mod_status.html">status module</A>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncwill notice that the server statistics are
941fd57f76689448d94928ce657a521e215f8671vboxsyncset to zero when a <CODE>HUP</CODE> is sent.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
941fd57f76689448d94928ce657a521e215f8671vboxsync<P><STRONG>Note:</STRONG> If your configuration file has errors in it when
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncyou issue a
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncrestart then your parent will not restart, it will exit with an error.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncSee below for a method of avoiding this.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
941fd57f76689448d94928ce657a521e215f8671vboxsync<H3>USR1 Signal: graceful restart</H3>
941fd57f76689448d94928ce657a521e215f8671vboxsync
941fd57f76689448d94928ce657a521e215f8671vboxsync<P><STRONG>Note:</STRONG> prior to release 1.2b9 this code is quite unstable
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncand shouldn't be used at all.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>The <CODE>USR1</CODE> signal causes the parent process to <EM>advise</EM>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncthe children to exit after their current request (or to exit immediately
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncif they're not serving anything). The parent re-reads its configuration
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncfiles and re-opens its log files. As each child dies off the parent
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncreplaces it with a child from the new <EM>generation</EM> of the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncconfiguration, which begins serving new requests immediately.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>This code is designed to always respect the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<A HREF="mod/core.html#maxclients">MaxClients</A>,
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<A HREF="mod/core.html#minspareservers">MinSpareServers</A>,
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncand <A HREF="mod/core.html#maxspareservers">MaxSpareServers</A> settings.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncFurthermore, it respects <A HREF="mod/core.html#startservers">StartServers</A>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncin the following manner: if after one second at least StartServers new
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncchildren have not been created, then create enough to pick up the slack.
e07acfb7f2dbb8bb40804024c79fd3139bdb3f24vboxsyncThis is to say that the code tries to maintain both the number of children
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncappropriate for the current load on the server, and respect your wishes
e07acfb7f2dbb8bb40804024c79fd3139bdb3f24vboxsyncwith the StartServers parameter.
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>Users of the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<A HREF="mod/mod_status.html">status module</A>
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncwill notice that the server statistics
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncare <STRONG>not</STRONG> set to zero when a <CODE>USR1</CODE> is sent. The
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsynccode
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncwas written to both minimize the time in which the server is unable to serve
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncnew requests (they will be queued up by the operating system, so they're
941fd57f76689448d94928ce657a521e215f8671vboxsyncnot lost in any event) and to respect your tuning parameters. In order
941fd57f76689448d94928ce657a521e215f8671vboxsyncto do this it has to keep the <EM>scoreboard</EM> used to keep track
941fd57f76689448d94928ce657a521e215f8671vboxsyncof all children across generations.
941fd57f76689448d94928ce657a521e215f8671vboxsync
941fd57f76689448d94928ce657a521e215f8671vboxsync<P>The status module will also use a <CODE>G</CODE> to indicate those
941fd57f76689448d94928ce657a521e215f8671vboxsyncchildren which are still serving requests started before the graceful
941fd57f76689448d94928ce657a521e215f8671vboxsyncrestart was given.
941fd57f76689448d94928ce657a521e215f8671vboxsync
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<P>At present there is no way for a log rotation script using
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsync<CODE>USR1</CODE> to know for certain that all children writing the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncpre-restart log have finished. We suggest that you use a suitable delay
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncafter sending the <CODE>USR1</CODE> signal before you do anything with the
16ad47ef7a806f45a9b210cea20014b946c4ca2avboxsyncold log. For example if most of your hits take less than 10 minutes to
complete for users on low bandwidth links then you could wait 15 minutes
before doing anything with the old log.
<P><STRONG>Note:</STRONG> If your configuration file has errors in it when
you issue a
restart then your parent will not restart, it will exit with an error.
In the case of graceful
restarts it will also leave children running when it exits. (These are
the children which are "gracefully exiting" by handling their last request.)
This will cause problems if you attempt to restart the server -- it will
not be able to bind to its listening ports. At present the only work
around is to check the syntax of your files before doing a restart. The
easiest way is to just run httpd as a non-root user. If there are no
errors it will attempt to open its sockets and logs and fail because it's
not root (or because the currently running httpd already has those ports
bound). If it fails for any other reason then it's probably a config file
error and the error should be fixed before issuing the graceful restart.
<H3>Appendix: signals and race conditions</H3>
<P>Prior to Apache 1.2b9 there were several <EM>race conditions</EM>
involving the restart and die signals (a simple description of race
condition is: a time-sensitive problem, as in if something happens at just
the wrong time it won't behave as expected). For those architectures that
have the "right" feature set we have eliminated as many as we can.
But it should be noted that there still do exist race conditions on
certain architectures.
<P>Architectures that use an on disk
<A HREF="mod/core.html#scoreboardfile">ScoreBoardFile</A>
have the potential to corrupt their scoreboards. This can result in
the "bind: Address already in use" (after <CODE>HUP</CODE>) or
"long lost child came home!" (after <CODE>USR1</CODE>). The former is
a fatal error, while the latter just causes the server to lose a scoreboard
slot. So it might be advisable to use graceful restarts, with
an occasional hard restart. These problems are very difficult to work
around, but fortunately most architectures do not require a scoreboard file.
See the ScoreBoardFile documentation for a method to determine if your
architecture uses it.
<P><CODE>NEXT</CODE> and <CODE>MACHTEN</CODE> (68k only) have small race
conditions
which can cause a restart/die signal to be lost, but should not cause the
server to do anything otherwise problematic.
<!-- they don't have sigaction, or we're not using it -djg -->
<P>All architectures have a small race condition in each child involving
the second and subsequent requests on a persistent HTTP connection
(KeepAlive). It may exit after reading the request line but before
reading any of the request headers. There is a fix that was discovered
too late to make 1.2. In theory this isn't an issue because the KeepAlive
client has to expect these events because of network latencies and
server timeouts. In practice it doesn't seem to affect anything either
-- in a test case the server was restarted twenty times per second and
clients successfully browsed the site without getting broken images or
empty documents.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>