If worker/master mode is active and the master process receives a SIGUSR2 then it will restart haproxy by re-reading the configuration file, killing existing workers and starting new workers.
SIGUSR2 is ignored if worker/master mode is not active. SIGUSR2 is ignored by worker processes. --- include/types/global.h | 1 + src/haproxy.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/types/global.h b/include/types/global.h index fecbeae..0739ca3 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -122,6 +122,7 @@ extern const int zero; extern const int one; extern const struct linger nolinger; extern int stopping; /* non zero means stopping in progress */ +extern int restarting; /* non zero means restart in progress */ extern int is_master; extern char hostname[MAX_HOSTNAME_LEN]; extern char localpeer[MAX_HOSTNAME_LEN]; diff --git a/src/haproxy.c b/src/haproxy.c index 3c20f92..076a7f4 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -137,6 +137,7 @@ struct global global_default = { /*********************************************************************/ int stopping; /* non zero means stopping in progress */ +int restarting; /* non zero means restart in progress */ int is_master = 0; /* non zero means that master/worker mode * has been activated and the current process * is the master */ @@ -276,6 +277,20 @@ void sig_soft_stop(struct sig_handler *sh) } /* + * upon SIGUSR2, restart master. Ignored by workers + */ +void sig_restart(struct sig_handler *sh) +{ + if (!is_master) + return; + + restarting = 1; + soft_stop(); + signal_unregister_handler(sh); + pool_gc2(); +} + +/* * upon SIGTTOU, we pause everything */ void sig_pause(struct sig_handler *sh) @@ -391,7 +406,7 @@ void init(int argc, char **argv) * Initialize the previously static variables. */ - totalconn = actconn = maxfd = listeners = stopping = 0; + totalconn = actconn = maxfd = listeners = stopping = restarting = 0; #ifdef HAPROXY_MEMMAX @@ -1406,7 +1421,18 @@ void run(int argc, char **argv) int main(int argc, char **argv) { - run(argc, argv); + while (1) { + run(argc, argv); + if (!restarting) + break; + } + + if (is_master) + /* The master is gracefully shutting down, + * ask the clients to gracefully shutdown too. + */ + tell_old_pids(SIGUSR1); + exit(0); } -- 1.7.2.3