]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: reintroduce systemd support
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Fri, 11 Oct 2024 17:36:32 +0000 (19:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Oct 2024 20:02:39 +0000 (22:02 +0200)
Let's reintroduce systemd support in the refactored master-worker mode.

As for now, the master-worker fork happens during early initialization steps and
then the master process receieves the "READY" status message from the newly
forked worker, that has successfully loaded. Let's propagate this "READY" status
message at this moment to the systemd from the master process context
(_send_status()). We use the master process to send messages to systemd,
because it is only the process, monitored by systemd.

In master recovery mode, we also need to send to the systemd the "READY"
message, but with the status "Reload failed". "READY" will signal to systemd,
that master process is still alive, because it doesn't exit in recovery mode
and it keeps the existed worker. Status "Reload failed" will signal to user,
that something wrong has happened with the configuration. Same message logic
was originally preserved for the case, when the worker fails to read its
configuration, see on_new_child_failure() for more details.

src/cli.c
src/haproxy.c

index a18ff8f23b24feab8a4b96f6b51a9d86f0de3908..57895769927f7f1e8ccec388cebe607f26e30cc2 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
 
 #include <net/if.h>
 
+#if defined(USE_SYSTEMD)
+#include <haproxy/systemd.h>
+#endif
+
 #include <haproxy/api.h>
 #include <haproxy/applet.h>
 #include <haproxy/base64.h>
@@ -2498,6 +2502,10 @@ static int _send_status(char **args, char *payload, struct appctx *appctx, void
        setenv("HAPROXY_LOAD_SUCCESS", "1", 1);
        ha_notice("Loading success.\n");
 
+#if defined(USE_SYSTEMD)
+       if (global.tune.options & GTUNE_USE_SYSTEMD)
+               sd_notifyf(0, "READY=1\nMAINPID=%lu\nSTATUS=Ready.\n", (unsigned long)getpid());
+#endif
        return 1;
 }
 
index d88d5fa27cdf7c68a8cc48c2f6e711c991c29f5b..4e25aedea9db85faede5ba930cf1d08007ce90ab 100644 (file)
@@ -3016,6 +3016,12 @@ static void run_master_in_recovery_mode(int argc, char **argv)
        list_for_each_entry(proc, &proc_list, list) {
                proc->failedreloads++;
        }
+#if defined(USE_SYSTEMD)
+       /* the sd_notify API is not able to send a reload failure signal. So
+        * the READY=1 signal still need to be sent */
+       if (global.tune.options & GTUNE_USE_SYSTEMD)
+               sd_notify(0, "READY=1\nSTATUS=Reload failed (master failed to load or to parse new configuration)!\n");
+#endif
 
        global.nbtgroups = 1;
        global.nbthread = 1;
@@ -4038,10 +4044,6 @@ int main(int argc, char **argv)
                ha_free(&msg);
        }
 
-#if defined(USE_SYSTEMD)
-       if (global.tune.options & GTUNE_USE_SYSTEMD)
-               sd_notifyf(0, "READY=1\nMAINPID=%lu\nSTATUS=Ready.\n", (unsigned long)getpid());
-#endif
        /* Finally, start the poll loop for the first thread */
        run_thread_poll_loop(&ha_thread_info[0]);