Skip to content

Commit

Permalink
Try to get a clean shutdown of a child for modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfclere committed Aug 31, 2023
1 parent b9e029c commit f6ff8d9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/mpm/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#include "http_vhost.h"
#include "unixd.h"
#include "apr_skiplist.h"
#include "ap_provider.h"
#include "util_time.h"

#include <signal.h>
Expand Down Expand Up @@ -1323,6 +1324,13 @@ static apr_status_t event_resume_suspended (conn_rec *c)
return OK;
}

/* hack to allow a module to restart gracefully child */
static void graceful_stop(void)
{
signal_threads(ST_GRACEFUL);
}


/* conns_this_child has gone to zero or below. See if the admin coded
"MaxConnectionsPerChild 0", and keep going in that case. Doing it this way
simplifies the hot path in worker_thread */
Expand Down Expand Up @@ -4270,6 +4278,8 @@ static void event_hooks(apr_pool_t * p)

ap_hook_pre_connection(event_pre_connection, NULL, NULL, APR_HOOK_REALLY_FIRST);
ap_hook_protocol_switch(event_protocol_switch, NULL, NULL, APR_HOOK_REALLY_FIRST);

ap_register_provider(p, "gracefull" , event_get_name(), "0", &graceful_stop);
}

static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
Expand Down
11 changes: 11 additions & 0 deletions server/mpm/prefork/prefork.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include "apr_poll.h"
#include "util_time.h"

#include "ap_provider.h"

#include <stdlib.h>

#ifdef HAVE_TIME_H
Expand Down Expand Up @@ -409,6 +411,13 @@ static void child_sigmask(sigset_t *new_mask, sigset_t *old_mask)
}
#endif

/* hack to allow a module to restart gracefully child */
static void graceful_stop(void)
{
clean_child_exit(0);
}


static void child_main(int child_num_arg, int child_bucket)
{
#if APR_HAS_THREADS
Expand Down Expand Up @@ -1510,6 +1519,8 @@ static void prefork_hooks(apr_pool_t *p)
ap_hook_mpm(prefork_run, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_query(prefork_query, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_get_name(prefork_get_name, NULL, NULL, APR_HOOK_MIDDLE);

ap_register_provider(p, "gracefull" , prefork_get_name(), "0", &graceful_stop);
}

static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy, const char *arg)
Expand Down
6 changes: 6 additions & 0 deletions server/mpm/winnt/child.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,12 @@ struct worker_info {
int num;
};

/* hack to allow a module to restart gracefully child */
void child_graceful_stop(void)
{
SetEvent(max_requests_per_child_event);
}

/*
* worker_thread()
* Main entry point for the worker threads. Worker threads block in
Expand Down
7 changes: 7 additions & 0 deletions server/mpm/winnt/mpm_winnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,11 @@ static int winnt_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
return OK; /* Restart */
}

static void graceful_stop(void)
{
child_graceful_stop();
}

static void winnt_hooks(apr_pool_t *p)
{
/* Our open_logs hook function must run before the core's, or stderr
Expand All @@ -1766,6 +1771,8 @@ static void winnt_hooks(apr_pool_t *p)
ap_hook_mpm(winnt_run, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_query(winnt_query, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_get_name(winnt_get_name, NULL, NULL, APR_HOOK_MIDDLE);

ap_register_provider(p, "gracefull" , winnt_get_name(), "0", &graceful_stop);
}

AP_DECLARE_MODULE(mpm_winnt) = {
Expand Down
10 changes: 10 additions & 0 deletions server/mpm/worker/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
#include "unixd.h"
#include "util_time.h"

#include "ap_provider.h"

#include <signal.h>
#include <limits.h> /* for INT_MAX */

Expand Down Expand Up @@ -492,6 +494,12 @@ static void process_socket(apr_thread_t *thd, apr_pool_t *p, apr_socket_t *sock,
}
}

/* hack to allow a module to restart gracefully child */
static void graceful_stop(void)
{
signal_threads(ST_GRACEFUL);
}

/* requests_this_child has gone to zero or below. See if the admin coded
"MaxConnectionsPerChild 0", and keep going in that case. Doing it this way
simplifies the hot path in worker_thread */
Expand Down Expand Up @@ -2361,6 +2369,8 @@ static void worker_hooks(apr_pool_t *p)
ap_hook_mpm(worker_run, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_query(worker_query, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_mpm_get_name(worker_get_name, NULL, NULL, APR_HOOK_MIDDLE);

ap_register_provider(p, "gracefull" , worker_get_name(), "0", &graceful_stop);
}

static const char *set_daemons_to_start(cmd_parms *cmd, void *dummy,
Expand Down

0 comments on commit f6ff8d9

Please sign in to comment.