]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: store and shows loading status
authorWilliam Lallemand <wlallemand@haproxy.org>
Sat, 24 Sep 2022 13:44:42 +0000 (15:44 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Sat, 24 Sep 2022 13:44:42 +0000 (15:44 +0200)
The environment variable HAPROXY_LOAD_SUCCESS stores "1" if it
successfully load the configuration and started, "0" otherwise.

The "_loadstatus" master CLI command displays either
"Loading failure!\n" or "Loading success.\n"

src/haproxy.c
src/mworker.c

index a837f48b90c572fc59c5b6a56bf570f73ce4e9a5..9b3b37f7b263ef008f498e6a486c245e578eec0d 100644 (file)
@@ -866,6 +866,7 @@ void reexec_on_failure()
        sock_drop_unused_old_sockets();
 
        usermsgs_clr(NULL);
+       setenv("HAPROXY_LOAD_SUCCESS", "0", 1);
        ha_warning("Loading failure!\n");
 #if defined(USE_SYSTEMD)
        /* the sd_notify API is not able to send a reload failure signal. So
@@ -3507,6 +3508,7 @@ int main(int argc, char **argv)
                                                sd_notifyf(0, "READY=1\nMAINPID=%lu\nSTATUS=Ready.\n", (unsigned long)getpid());
 #endif
                                        /* if not in wait mode, reload in wait mode to free the memory */
+                                       setenv("HAPROXY_LOAD_SUCCESS", "1", 1);
                                        ha_notice("Loading success.\n");
                                        proc_self->failedreloads = 0; /* reset the number of failure */
                                        mworker_reexec_waitmode();
index 49113df62bdd40d5e0a66fe28b3473827d0d7e99..e613a4e1640376f6af5c55c7693cf02b167b42e3 100644 (file)
@@ -31,6 +31,7 @@
 #include <haproxy/fd.h>
 #include <haproxy/global.h>
 #include <haproxy/list.h>
+#include <haproxy/log.h>
 #include <haproxy/listener.h>
 #include <haproxy/mworker.h>
 #include <haproxy/peers.h>
@@ -656,6 +657,28 @@ 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)
+{
+       char *env;
+
+       if (!cli_has_level(appctx, ACCESS_LVL_OPER))
+               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");
+       } else if (strcmp(env, "1") == 0) {
+               return cli_msg(appctx, LOG_INFO, "Loading success.\n");
+       }
+
+       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)
@@ -714,6 +737,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},
        {{},}
 }};