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.
This commit is contained in:
William Lallemand 2018-12-14 21:11:31 +01:00 committed by Willy Tarreau
parent 52880f97b9
commit a57b7e33ef
4 changed files with 24 additions and 1 deletions

View File

@ -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
----------------------------------------------

View File

@ -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) \

View File

@ -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 },
{{},}
}};

View File

@ -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;