]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker/cli: reload command displays the startup-logs
authorWilliam Lallemand <wlallemand@haproxy.org>
Thu, 13 Oct 2022 15:49:54 +0000 (17:49 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 13 Oct 2022 15:59:48 +0000 (17:59 +0200)
Change the output of the "reload" command, it now displays "Success=0"
if the reload failed and "Success=1" if it succeed.

If the startup-logs is available (USE_SHM_OPEN=1), the command will
print a "--\n" line, followed by the content of the startup-logs.

Example:

$ echo "reload" | socat /tmp/master.sock -
Success=1
--
[NOTICE]   (482713) : haproxy version is 2.7-dev7-4827fb-69
[NOTICE]   (482713) : path to executable is ./haproxy
[WARNING]  (482713) : config : 'http-request' rules ignored for proxy 'frt1' as they require HTTP mode.
[NOTICE]   (482713) : New worker (482720) forked
[NOTICE]   (482713) : Loading success.

$ echo "reload" | socat /tmp/master.sock -
Success=0
--
[NOTICE]   (482886) : haproxy version is 2.7-dev7-4827fb-69
[NOTICE]   (482886) : path to executable is ./haproxy
[ALERT]    (482886) : config : parsing [test3.cfg:1]: unknown keyword 'Aglobal' out of section.
[ALERT]    (482886) : config : Fatal errors found in configuration.
[WARNING]  (482886) : Loading failure!

$

src/mworker.c

index e613a4e1640376f6af5c55c7693cf02b167b42e3..40086da7397bd233b1083f19a5ec031318fef11d 100644 (file)
@@ -37,6 +37,7 @@
 #include <haproxy/peers.h>
 #include <haproxy/proto_sockpair.h>
 #include <haproxy/proxy.h>
+#include <haproxy/ring.h>
 #include <haproxy/sc_strm.h>
 #include <haproxy/signal.h>
 #include <haproxy/stconn.h>
@@ -657,28 +658,43 @@ static int cli_parse_reload(char **args, char *payload, struct appctx *appctx, v
        return 1;
 }
 
-/* Displays if the current reload failed or succeed  */
-static int cli_parse_status(char **args, char *payload, struct appctx *appctx, void *private)
+/* Displays if the current reload failed or succeed.
+ * If the startup-logs is available, dump it.  */
+static int cli_io_handler_show_status(struct appctx *appctx)
 {
        char *env;
+       struct stconn *sc = appctx_sc(appctx);
 
        if (!cli_has_level(appctx, ACCESS_LVL_OPER))
                return 1;
 
+       if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
+               return 1;
+
+
        env = getenv("HAPROXY_LOAD_SUCCESS");
        if (!env)
                return 1;
 
        if (strcmp(env, "0") == 0) {
-               return cli_msg(appctx, LOG_INFO, "Loading failure!\n");
+               chunk_printf(&trash, "Success=0\n");
        } else if (strcmp(env, "1") == 0) {
-               return cli_msg(appctx, LOG_INFO, "Loading success.\n");
+               chunk_printf(&trash, "Success=1\n");
        }
 
-       return 1;
-}
+       if (startup_logs && b_data(&startup_logs->buf) > 1)
+               chunk_appendf(&trash, "--\n");
 
+       if (applet_putchk(appctx, &trash) == -1)
+               return 0;
 
+       if (startup_logs) {
+               appctx->io_handler = NULL;
+               ring_attach_cli(startup_logs, appctx, 0);
+               return 0;
+       }
+       return 1;
+}
 
 static int mworker_parse_global_max_reloads(char **args, int section_type, struct proxy *curpx,
            const struct proxy *defpx, const char *file, int linenum, char **err)
@@ -737,7 +753,7 @@ static struct cli_kw_list cli_kws = {{ },{
        { { "@master", NULL },         "@master                                 : send a command to the master process", cli_parse_default, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
        { { "show", "proc", NULL },    "show proc                               : show processes status", cli_parse_default, cli_io_handler_show_proc, NULL, NULL, ACCESS_MASTER_ONLY},
        { { "reload", NULL },          "reload                                  : reload haproxy", cli_parse_reload, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
-       { { "_loadstatus", NULL },     NULL,                                                             cli_parse_status, NULL, NULL, NULL, ACCESS_MASTER_ONLY},
+       { { "_loadstatus", NULL },     NULL,                                                             cli_parse_default, cli_io_handler_show_status, NULL, NULL, ACCESS_MASTER_ONLY},
        {{},}
 }};