]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: implements 'reload' on master CLI
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 14 Dec 2018 20:11:31 +0000 (21:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 15 Dec 2018 12:33:49 +0000 (13:33 +0100)
The reload command reload the haproxy master like it is done with a kill
-USR2 on the master process.

doc/management.txt
include/types/global.h
src/cli.c
src/haproxy.c

index 21719f475bcd3d9ab2a50b20928f855984811ad2..a01ba96c9db2eaf337e51b98d03cfc2d0494ab72 100644 (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
 ----------------------------------------------
index 0d1c4e2e71825127078779f29b9511a00800a04f..16fce723ef157ea17e0c2231e854ea43d1d2d4e0 100644 (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) \
index 1a2253c49207c36fcbc72004a7cdbbfce137022d..23caac3b7758fad5fa4e3947a3af95719b6a2807 100644 (file)
--- 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 },
        {{},}
 }};
index 20fc1dece711061402053d5bc294672de1932887..994e39ca9948f52245cb5787eb1f3ad0e85c08df 100644 (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;