httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r264105 - in /httpd/httpd/trunk: ./ docs/manual/ docs/manual/mod/ server/mpm/experimental/event/
Date Mon, 29 Aug 2005 10:20:38 GMT
Author: colm
Date: Mon Aug 29 03:20:25 2005
New Revision: 264105

URL: http://svn.apache.org/viewcvs?rev=264105&view=rev
Log:

Implement graceful stop in the event MPM. Implementation is identical to
the worker MPM implementation. 


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/mod/mpm_common.html.en
    httpd/httpd/trunk/docs/manual/mod/mpm_common.xml
    httpd/httpd/trunk/docs/manual/new_features_2_2.html.en
    httpd/httpd/trunk/docs/manual/new_features_2_2.xml
    httpd/httpd/trunk/docs/manual/new_features_2_2.xml.ko
    httpd/httpd/trunk/docs/manual/new_features_2_2.xml.pt-br
    httpd/httpd/trunk/server/mpm/experimental/event/event.c
    httpd/httpd/trunk/server/mpm/experimental/event/mpm.h

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/CHANGES?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Mon Aug 29 03:20:25 2005
@@ -4,7 +4,7 @@
 
   *) Doxygen fixup [Neale Ranns neale ranns.org, Ian Holsman]
 
-  *) prefork and worker MPMs: Support a graceful-stop procedure:
+  *) prefork, worker and event MPMs: Support a graceful-stop procedure:
      Server will wait until existing requests are finished or until  
      "GracefulShutdownTimeout" number of seconds before exiting. 
      [Colm MacCarthaigh, Ken Coar, Bill Stoddard]
@@ -12,8 +12,8 @@
   *) mod_cgid: Append .PID to the script socket filename and remove the
      script socket on exit. [Colm MacCarthaigh]
 
-  *) prefork and worker MPMs: Prevent children from holding open listening
-     ports upon graceful restart or stop. PR28167. 
+  *) prefork, worker and event MPMs: Prevent children from holding open 
+     listening ports upon graceful restart or stop. PR28167. 
      [Colm MacCarthaigh, Brian Pinkerton <bp thinkpink.com>]
 
   *) Linux 2.0: remove support for threaded MPM's due to linuxthreads use

Modified: httpd/httpd/trunk/docs/manual/mod/mpm_common.html.en
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/mod/mpm_common.html.en?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mpm_common.html.en (original)
+++ httpd/httpd/trunk/docs/manual/mod/mpm_common.html.en Mon Aug 29 03:20:25 2005
@@ -181,7 +181,7 @@
 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>GracefulShutDownTimeout
0</code></td></tr>
 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server
config</td></tr>
 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>MPM</td></tr>
-<tr><th><a href="directive-dict.html#Module">Module:</a></th><td><code
class="module"><a href="../mod/prefork.html">prefork</a></code>, <code
class="module"><a href="../mod/worker.html">worker</a></code></td></tr>
+<tr><th><a href="directive-dict.html#Module">Module:</a></th><td><code
class="module"><a href="../mod/prefork.html">prefork</a></code>, <code
class="module"><a href="../mod/worker.html">worker</a></code>, <code
class="module"><a href="../mod/event.html">event</a></code></td></tr>
 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Available
in version 2.2 and later</td></tr>
 </table>
     <p>The <code class="directive">GracefulShutdownTimeout</code> specifies

Modified: httpd/httpd/trunk/docs/manual/mod/mpm_common.xml
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/mod/mpm_common.xml?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mpm_common.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mpm_common.xml Mon Aug 29 03:20:25 2005
@@ -163,7 +163,8 @@
 <syntax>GracefulShutDownTimeout <var>seconds</var></syntax>
 <default>GracefulShutDownTimeout 0</default>
 <contextlist><context>server config</context></contextlist>
-<modulelist><module>prefork</module><module>worker</module></modulelist>
+<modulelist><module>prefork</module><module>worker</module>
+<module>event</module></modulelist>
 <compatibility>Available in version 2.2 and later</compatibility>
 
 <usage>

Modified: httpd/httpd/trunk/docs/manual/new_features_2_2.html.en
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/new_features_2_2.html.en?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/new_features_2_2.html.en (original)
+++ httpd/httpd/trunk/docs/manual/new_features_2_2.html.en Mon Aug 29 03:20:25 2005
@@ -53,8 +53,9 @@
           setups.</dd>
 
       <dt>Graceful stop</dt>
-      <dd>The <code class="module"><a href="./mod/prefork.html">prefork</a></code>
and <code class="module"><a href="./mod/worker.html">worker</a></code>
MPMs now
-          allow <code class="program"><a href="./programs/httpd.html">httpd</a></code>
to be shutdown gracefully via the
+      <dd>The <code class="module"><a href="./mod/prefork.html">prefork</a></code>,
<code class="module"><a href="./mod/worker.html">worker</a></code>
and 
+          <code class="module"><a href="./mod/event.html">event</a></code>
 MPMs now allow <code class="program"><a href="./programs/httpd.html">httpd</a></code>

+          to be shutdown gracefully via the
           <a href="stopping.html#gracefulstop"><code>graceful-stop</code></a>

           signal. The <code class="directive"><a href="./mod/mpm_common.html#gracefulshutdowntimeout">GracefulShutdownTimeout</a></code>
directive
           has been added to specify an optional timeout, after which

Modified: httpd/httpd/trunk/docs/manual/new_features_2_2.xml
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/new_features_2_2.xml?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/new_features_2_2.xml (original)
+++ httpd/httpd/trunk/docs/manual/new_features_2_2.xml Mon Aug 29 03:20:25 2005
@@ -49,8 +49,9 @@
           setups.</dd>
 
       <dt>Graceful stop</dt>
-      <dd>The <module>prefork</module> and <module>worker</module>
MPMs now
-          allow <program>httpd</program> to be shutdown gracefully via the
+      <dd>The <module>prefork</module>, <module>worker</module>
and 
+          <module>event</module>  MPMs now allow <program>httpd</program>

+          to be shutdown gracefully via the
           <a href="stopping.html#gracefulstop"><code>graceful-stop</code></a>

           signal. The <directive 
           module="mpm_common">GracefulShutdownTimeout</directive> directive

Modified: httpd/httpd/trunk/docs/manual/new_features_2_2.xml.ko
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/new_features_2_2.xml.ko?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/new_features_2_2.xml.ko [euc-kr] (original)
+++ httpd/httpd/trunk/docs/manual/new_features_2_2.xml.ko [euc-kr] Mon Aug 29 03:20:25 2005
@@ -1,7 +1,7 @@
 <?xml version='1.0' encoding='EUC-KR' ?>
 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
 <?xml-stylesheet type="text/xsl" href="./style/manual.ko.xsl"?>
-<!-- English Revision: 105989:193026 (outdated) -->
+<!-- English Revision: 105989:263906 (outdated) -->
 
 <!--
  Copyright 2004-2005 The Apache Software Foundation or its licensors,

Modified: httpd/httpd/trunk/docs/manual/new_features_2_2.xml.pt-br
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/docs/manual/new_features_2_2.xml.pt-br?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/new_features_2_2.xml.pt-br (original)
+++ httpd/httpd/trunk/docs/manual/new_features_2_2.xml.pt-br Mon Aug 29 03:20:25 2005
@@ -1,7 +1,7 @@
 <?xml version='1.0' encoding='UTF-8' ?>
 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
 <?xml-stylesheet type="text/xsl" href="./style/manual.pt-br.xsl"?>
-<!-- English Revision: 151408:193026 (outdated) -->
+<!-- English Revision: 151408:263906 (outdated) -->
 
 <!--
  Copyright 2005 The Apache Software Foundation or its licensors,

Modified: httpd/httpd/trunk/server/mpm/experimental/event/event.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/server/mpm/experimental/event/event.c?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/experimental/event/event.c (original)
+++ httpd/httpd/trunk/server/mpm/experimental/event/event.c Mon Aug 29 03:20:25 2005
@@ -416,7 +416,7 @@
  * child to force an exit) and so do an exit anyway.
  */
 
-static void ap_start_shutdown(void)
+static void ap_start_shutdown(int graceful)
 {
     mpm_state = AP_MPMQ_STOPPING;
     if (shutdown_pending == 1) {
@@ -427,6 +427,7 @@
         return;
     }
     shutdown_pending = 1;
+    is_graceful = graceful;
 }
 
 /* do a graceful restart if graceful == 1 */
@@ -443,7 +444,7 @@
 
 static void sig_term(int sig)
 {
-    ap_start_shutdown();
+    ap_start_shutdown(sig == AP_SIG_GRACEFUL_STOP);
 }
 
 static void restart(int sig)
@@ -469,6 +470,11 @@
     if (sigaction(SIGTERM, &sa, NULL) < 0)
         ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
                      "sigaction(SIGTERM)");
+#ifdef AP_SIG_GRACEFUL_STOP
+    if (sigaction(AP_SIG_GRACEFUL_STOP, &sa, NULL) < 0)
+        ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
+                     "sigaction(" AP_SIG_GRACEFUL_STOP_STRING ")");
+#endif
 #ifdef SIGINT
     if (sigaction(SIGINT, &sa, NULL) < 0)
         ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,
@@ -521,6 +527,9 @@
 #ifdef AP_SIG_GRACEFUL
     apr_signal(AP_SIG_GRACEFUL, restart);
 #endif /* AP_SIG_GRACEFUL */
+#ifdef AP_SIG_GRACEFUL_STOP
+     apr_signal(AP_SIG_GRACEFUL_STOP, sig_term);
+#endif /* AP_SIG_GRACEFUL_STOP */
 #ifdef SIGPIPE
     apr_signal(SIGPIPE, SIG_IGN);
 #endif /* SIGPIPE */
@@ -1036,6 +1045,7 @@
 
     }     /* listener main loop */
 
+    ap_close_listeners();
     ap_queue_term(worker_queue);
     dying = 1;
     ap_scoreboard_image->parent[process_slot].quiescing = 1;
@@ -1924,11 +1934,9 @@
     server_main_loop(remaining_children_to_start);
     mpm_state = AP_MPMQ_STOPPING;
 
-    if (shutdown_pending) {
-        /* Time to gracefully shut down:
+    if (shutdown_pending && !is_graceful) {
+        /* Time to shut down:
          * Kill child processes, tell them to call child_exit, etc...
-         * (By "gracefully" we don't mean graceful in the same sense as 
-         * "apachectl graceful" where we allow old connections to finish.)
          */
         ap_mpm_pod_killpg(pod, ap_daemons_limit, FALSE);
         ap_reclaim_child_processes(1);  /* Start with SIGTERM */
@@ -1947,7 +1955,64 @@
                          ap_server_conf, "caught SIGTERM, shutting down");
         }
         return 1;
-    }
+    } else if (shutdown_pending) {
+        /* Time to gracefully shut down:
+         * Kill child processes, tell them to call child_exit, etc...
+         */
+        int active_children;
+        int index;
+        apr_time_t cutoff = 0;
+
+        /* Close our listeners, and then ask our children to do same */
+        ap_close_listeners();
+        ap_mpm_pod_killpg(pod, ap_daemons_limit, TRUE);
+        ap_relieve_child_processes();
+
+        if (!child_fatal) {
+            /* cleanup pid file on normal shutdown */
+            const char *pidfile = NULL;
+            pidfile = ap_server_root_relative (pconf, ap_pid_fname);
+            if ( pidfile != NULL && unlink(pidfile) == 0)
+                ap_log_error(APLOG_MARK, APLOG_INFO, 0,
+                             ap_server_conf,
+                             "removed PID file %s (pid=%ld)",
+                             pidfile, (long)getpid());
+
+            ap_log_error(APLOG_MARK, APLOG_NOTICE, 0,
+                         ap_server_conf, "caught SIGTERM, shutting down");
+        }
+
+        /* Don't really exit until each child has finished */
+        shutdown_pending = 0;
+        do {
+            /* Pause for a second */
+            apr_sleep(apr_time_from_sec(1));
+
+            /* Relieve any children which have now exited */
+            ap_relieve_child_processes();
+
+            active_children = 0;
+            for (index = 0; index < ap_daemons_limit; ++index) {
+                if (MPM_CHILD_PID(index) != 0) {
+                    if (kill(MPM_CHILD_PID(index), 0) == 0) {
+                            active_children = 1;
+                            /* Having just one child is enough to stay around */
+                            break;
+                    }
+                }
+            }
+        } while (!shutdown_pending && active_children &&
+                 (!ap_graceful_shutdown_timeout || apr_time_now() < cutoff));
+
+        /* We might be here because we received SIGTERM, either
+         * way, try and make sure that all of our processes are
+         * really dead.
+         */
+        ap_mpm_pod_killpg(pod, ap_daemons_limit, FALSE);
+        ap_reclaim_child_processes(1);
+
+        return 1;
+    } 
 
     /* we've been told to restart */
     apr_signal(SIGHUP, SIG_IGN);
@@ -2370,6 +2435,7 @@
     AP_INIT_TAKE1("ThreadLimit", set_thread_limit, NULL, RSRC_CONF,
                   "Maximum number of worker threads per child process for this "
                   "run of Apache - Upper limit for ThreadsPerChild"),
+    AP_GRACEFUL_SHUTDOWN_TIMEOUT_COMMAND,
     {NULL}
 };
 

Modified: httpd/httpd/trunk/server/mpm/experimental/event/mpm.h
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/server/mpm/experimental/event/mpm.h?rev=264105&r1=264104&r2=264105&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/experimental/event/mpm.h (original)
+++ httpd/httpd/trunk/server/mpm/experimental/event/mpm.h Mon Aug 29 03:20:25 2005
@@ -45,6 +45,7 @@
 #define AP_MPM_WANT_SIGNAL_SERVER
 #define AP_MPM_WANT_SET_MAX_MEM_FREE
 #define AP_MPM_WANT_SET_STACKSIZE
+#define AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
 #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER
 #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK
 



Mime
View raw message