From a57b7e33ef5587562873897aea9c91470a206220 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 14 Dec 2018 21:11:31 +0100 Subject: [PATCH] MINOR: cli: implements 'reload' on master CLI The reload command reload the haproxy master like it is done with a kill -USR2 on the master process. --- doc/management.txt | 10 ++++++++++ include/types/global.h | 1 + src/cli.c | 12 ++++++++++++ src/haproxy.c | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/management.txt b/doc/management.txt index 21719f475..a01ba96c9 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -2588,6 +2588,16 @@ Examples: $ echo '@1; show info; show stat; @2; show info; show stat' | socat /var/run/haproxy-master.sock - [...] +You can also reload the HAProxy master process with the "reload" command which +does the same as a `kill -USR2` on the master process, provided that the user +has at least "operator" or "admin" privileges. + +Example: + + $ echo "reload" | socat /var/run/haproxy-master.sock + +Note that a reload will close the connection to the master CLI. + 10. Tricks for easier configuration management ---------------------------------------------- diff --git a/include/types/global.h b/include/types/global.h index 0d1c4e2e7..16fce723e 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -247,6 +247,7 @@ void hap_register_per_thread_init(int (*fct)()); void hap_register_per_thread_deinit(void (*fct)()); void mworker_accept_wrapper(int fd); +void mworker_reload(); /* simplified way to declare static build options in a file */ #define REGISTER_BUILD_OPTS(str) \ diff --git a/src/cli.c b/src/cli.c index 1a2253c49..23caac3b7 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1318,6 +1318,17 @@ static int cli_parse_set_lvl(char **args, char *payload, struct appctx *appctx, return 1; } +/* reload the master process */ +static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, void *private) +{ + if (!cli_has_level(appctx, ACCESS_LVL_OPER)) + return 1; + + mworker_reload(); + + return 1; +} + int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private) { return 0; @@ -2619,6 +2630,7 @@ static struct cli_kw_list cli_kws = {{ },{ { { "show", "proc", NULL }, "show proc : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY}, { { "operator", NULL }, "operator : lower the level of the current CLI session to operator", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER}, { { "user", NULL }, "user : lower the level of the current CLI session to user", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER}, + { { "reload", NULL }, "reload : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY}, { { "_getsocks", NULL }, NULL, _getsocks, NULL }, {{},} }}; diff --git a/src/haproxy.c b/src/haproxy.c index 20fc1dece..994e39ca9 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -708,7 +708,7 @@ static void get_cur_unixsocket() * When called, this function reexec haproxy with -sf followed by current * children PIDs and possibly old children PIDs if they didn't leave yet. */ -static void mworker_reload() +void mworker_reload() { int next_argc = 0; int j;