From 4c8303a59e8cd75a50f293e2bd6e2c3c4db2eda4 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Fri, 11 Oct 2024 19:36:32 +0200 Subject: [PATCH] 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. --- src/cli.c | 8 ++++++++ src/haproxy.c | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cli.c b/src/cli.c index a18ff8f23..578957699 100644 --- a/src/cli.c +++ b/src/cli.c @@ -26,6 +26,10 @@ #include +#if defined(USE_SYSTEMD) +#include +#endif + #include #include #include @@ -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; } diff --git a/src/haproxy.c b/src/haproxy.c index d88d5fa27..4e25aedea 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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]);