From ec1f8a62cab5666d0aa6b5cd8513b2661ce6d8fd Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 13 Oct 2022 17:49:54 +0200 Subject: [PATCH] MINOR: mworker/cli: reload command displays the startup-logs 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 | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mworker.c b/src/mworker.c index e613a4e16..40086da73 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -657,29 +658,44 @@ 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"); } + 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}, {{},} }};