]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: systemd: Include MONOTONIC_USEC field in RELOADING=1 message
authorTim Duesterhus <tim@bastelstu.be>
Wed, 3 Apr 2024 20:39:16 +0000 (22:39 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 4 Apr 2024 13:58:29 +0000 (15:58 +0200)
As per the `sd_notify` manual:

> A field carrying the monotonic timestamp (as per CLOCK_MONOTONIC) formatted
> in decimal in μs, when the notification message was generated by the client.
> This is typically used in combination with "RELOADING=1", to allow the
> service manager to properly synchronize reload cycles. See systemd.service(5)
> for details, specifically "Type=notify-reload".

Thus this change allows users with a recent systemd to switch to
`Type=notify-reload`, should they desire to do so. Correct behavior was
verified with a Fedora 39 VM.

see systemd/systemd#25916

[wla: the service file should be updated this way:]

    diff --git a/admin/systemd/haproxy.service.in b/admin/systemd/haproxy.service.in
    index 22a53d8aab..8c6dadb5e5 100644
    --- a/admin/systemd/haproxy.service.in
    +++ b/admin/systemd/haproxy.service.in
    @@ -8,12 +8,11 @@ EnvironmentFile=-/etc/default/haproxy
     EnvironmentFile=-/etc/sysconfig/haproxy
     Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock"
     ExecStart=@SBINDIR@/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
    -ExecReload=@SBINDIR@/haproxy -Ws -f $CONFIG -c $EXTRAOPTS
    -ExecReload=/bin/kill -USR2 $MAINPID
     KillMode=mixed
     Restart=always
     SuccessExitStatus=143
    -Type=notify
    +Type=notify-reload
    +ReloadSignal=SIGUSR2

     # The following lines leverage SystemD's sandboxing options to provide
     # defense in depth protection at the expense of restricting some flexibility

Signed-off-by: William Lallemand <wlallemand@haproxy.com>
src/haproxy.c

index 0fcc3e54160514d18677953ec8e235f6297947b4..a5f1e79ef972d1fa1e9170bad527ddc3704b31be 100644 (file)
@@ -844,8 +844,17 @@ void mworker_reload(int hardreload)
        }
 
 #if defined(USE_SYSTEMD)
-       if (global.tune.options & GTUNE_USE_SYSTEMD)
-               sd_notify(0, "RELOADING=1\nSTATUS=Reloading Configuration.\n");
+       if (global.tune.options & GTUNE_USE_SYSTEMD) {
+               struct timespec ts;
+
+               (void)clock_gettime(CLOCK_MONOTONIC, &ts);
+
+               sd_notifyf(0,
+                          "RELOADING=1\n"
+                              "STATUS=Reloading Configuration.\n"
+                              "MONOTONIC_USEC=%" PRIu64 "\n",
+                          (ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL));
+       }
 #endif
        mworker_reexec(hardreload);
 }