MINOR: mworker: reintroduce systemd support

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.
This commit is contained in:
Valentine Krasnobaeva 2024-10-11 19:36:32 +02:00 committed by Willy Tarreau
parent 9e23cfa5c2
commit 4c8303a59e
2 changed files with 14 additions and 4 deletions

View File

@ -26,6 +26,10 @@
#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;
}

View 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]);