MINOR: mworker: store and shows loading status
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"
diff --git a/src/haproxy.c b/src/haproxy.c
index a837f48..9b3b37f 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -866,6 +866,7 @@
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 @@
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();
diff --git a/src/mworker.c b/src/mworker.c
index 49113df..e613a4e 100644
--- a/src/mworker.c
+++ b/src/mworker.c
@@ -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 @@
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 @@
{ { "@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},
{{},}
}};