From d7c04b158cd499836084e730abe72f98eb18549e Mon Sep 17 00:00:00 2001 From: Colm MacCarthaigh Date: Fri, 26 Aug 2005 17:43:24 +0000 Subject: [PATCH] Move the "GracefulShutdownTimeout" directive into mpm_common, for re-use with other MPM's. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@240296 13f79535-47bb-0310-9956-ffa450edef68 --- include/mpm_common.h | 10 ++++++++++ server/main.c | 4 ++-- server/mpm/prefork/mpm.h | 2 +- server/mpm/prefork/prefork.c | 25 +++++++------------------ server/mpm_common.c | 17 ++++++++++++++++- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/include/mpm_common.h b/include/mpm_common.h index 478810d052..91fd0bd4c7 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -287,6 +287,16 @@ const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, const char *arg); #endif +/** + * Set the timeout period for a graceful shutdown. + */ +#ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN +extern int ap_graceful_shutdown_timeout; +const char *ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, + const char *arg); +#endif + + #ifdef AP_MPM_WANT_SIGNAL_SERVER int ap_signal_server(int *, apr_pool_t *); void ap_mpm_rewrite_args(process_rec *); diff --git a/server/main.c b/server/main.c index c73a315d29..9808581921 100644 --- a/server/main.c +++ b/server/main.c @@ -318,7 +318,7 @@ static void usage(process_rec *process) pad); #endif #ifdef AP_MPM_WANT_SIGNAL_SERVER -#ifdef AP_MPM_SUPPORTS_GRACEFUL_STOP +#ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " %s [-k start|restart|graceful|graceful-stop|stop]", pad); @@ -326,7 +326,7 @@ static void usage(process_rec *process) ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " %s [-k start|restart|graceful|stop]", pad); -#endif /* AP_MPM_SUPPORTS_GRACEFUL_STOP */ +#endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */ #endif ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " %s [-v] [-V] [-h] [-l] [-L] [-t] [-S]", pad); diff --git a/server/mpm/prefork/mpm.h b/server/mpm/prefork/mpm.h index b9ab6ebc56..cead8b9683 100644 --- a/server/mpm/prefork/mpm.h +++ b/server/mpm/prefork/mpm.h @@ -38,8 +38,8 @@ #define AP_MPM_WANT_SIGNAL_SERVER #define AP_MPM_WANT_SET_MAX_MEM_FREE #define AP_MPM_WANT_FATAL_SIGNAL_HANDLER +#define AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN #define AP_MPM_DISABLE_NAGLE_ACCEPTED_SOCK -#define AP_MPM_SUPPORTS_GRACEFUL_STOP #define AP_MPM_USES_POD 1 #define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 66067ab822..94d15497aa 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -96,7 +96,6 @@ static int ap_daemons_to_start=0; static int ap_daemons_min_free=0; static int ap_daemons_max_free=0; static int ap_daemons_limit=0; /* MaxClients */ -static int graceful_shutdown_timeout = 0; static int server_limit = DEFAULT_SERVER_LIMIT; static int first_server_limit; static int changed_limit_at_restart; @@ -1122,7 +1121,7 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) int status; int child_slot; apr_proc_t pid; - apr_time_t cutoff; + apr_time_t cutoff = 0; /* Stop listening */ ap_close_listeners(); @@ -1168,9 +1167,9 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "caught " AP_SIG_GRACEFUL_STOP_STRING ", shutting down gracefully"); - if (graceful_shutdown_timeout) { + if (ap_graceful_shutdown_timeout) { cutoff = apr_time_now() + - apr_time_from_sec(graceful_shutdown_timeout); + apr_time_from_sec(ap_graceful_shutdown_timeout); } /* Don't really exit until each child has finished */ @@ -1198,7 +1197,7 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s) } } } while (!shutdown_pending && active_children && - (!graceful_shutdown_timeout || apr_time_now() < cutoff)); + (!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 @@ -1473,16 +1472,6 @@ static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *ar return NULL; } -static const char *set_graceful_shutdown(cmd_parms *cmd, void *dummy, const char *arg) -{ - const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); - if (err != NULL) { - return err; - } - graceful_shutdown_timeout = atoi(arg); - return NULL; -} - static const command_rec prefork_cmds[] = { UNIX_DAEMON_COMMANDS, LISTEN_COMMANDS, @@ -1496,9 +1485,9 @@ AP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF, "Maximum number of children alive at the same time"), AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF, "Maximum value of MaxClients for this run of Apache"), -AP_INIT_TAKE1("GracefulShutdownTimeout", set_graceful_shutdown, NULL, RSRC_CONF, - "Time in seconds to wait for child processes to complete " - "transactions during shutdown"), +AP_INIT_TAKE1("GracefulShutdownTimeout", ap_mpm_set_graceful_shutdown, NULL, + RSRC_CONF, "Time in seconds to wait for child processes to " + "complete transactions during shutdown"), { NULL } }; diff --git a/server/mpm_common.c b/server/mpm_common.c index e8a8cb44a4..52aebd478a 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -760,6 +760,21 @@ const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy, } #endif +#ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN +int ap_graceful_shutdown_timeout = 0; + +const char * ap_mpm_set_graceful_shutdown(cmd_parms *cmd, void *dummy, + const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + if (err != NULL) { + return err; + } + ap_graceful_shutdown_timeout = atoi(arg); + return NULL; +} +#endif + #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH apr_lockmech_e ap_accept_lock_mech = APR_LOCK_DEFAULT; @@ -923,7 +938,7 @@ int ap_signal_server(int *exit_status, apr_pool_t *pconf) } if (!strcmp(dash_k_arg, "graceful-stop")) { -#ifdef AP_MPM_SUPPORTS_GRACEFUL_STOP +#ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN if (!running) { printf("%s\n", status); } -- 2.40.0