implement notify-reload protocol correctly

See https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html

which now has a full python  and C example of the wire protocol

You should be setting `MONOTONIC_TIMESTAMP` in the same message as `RELOADING=1` not separate message


so:


```
sd_notify("RELOADING=1\nMONOTONIC_TIMESTAMP=xxxx")
sleep(5)
sd_notify("READY=1")
```

as opposed to what you're doing now:

```
sd_notify("RELOADING=1")
sd_notify("MONOTONIC_TIMESTAMP=xxxx")
sleep(5)
sd_notify("READY=1")
sd_notify("MONOTONIC_TIMESTAMP=xxxx")
```

I edited this in my browser.  The indentation of this file looks really broken. not sure why
This commit is contained in:
Arian van Putten 2025-04-02 19:36:43 +01:00 committed by GitHub
parent 82a883089f
commit df8559e245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -724,14 +724,6 @@ async fn kanidm_main(config: Configuration, opt: KanidmdParser) -> ExitCode {
#[cfg(target_os = "linux")]
{
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Ready]);
// Undocumented systemd feature - all messages should have a monotonic usec sent
// with them. In some cases like "reloading" messages, it is undocumented but
// failure to send this message causes the reload to fail.
if let Ok(monotonic_usec) = sd_notify::NotifyState::monotonic_usec_now() {
let _ = sd_notify::notify(true, &[monotonic_usec]);
} else {
error!("CRITICAL!!! Unable to access clock monotonic time. SYSTEMD WILL KILL US.");
};
let _ = sd_notify::notify(
true,
&[sd_notify::NotifyState::Status("Started Kanidm 🦀")],
@ -771,15 +763,11 @@ async fn kanidm_main(config: Configuration, opt: KanidmdParser) -> ExitCode {
// systemd has a special reload handler for this.
#[cfg(target_os = "linux")]
{
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Reloading]);
// CRITICAL - if you do not send a monotonic usec message after a reloading
// message, your service WILL BE KILLED.
if let Ok(monotonic_usec) = sd_notify::NotifyState::monotonic_usec_now() {
let _ =
sd_notify::notify(true, &[monotonic_usec]);
} else {
else {
error!("CRITICAL!!! Unable to access clock monotonic time. SYSTEMD WILL KILL US.");
};
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Reloading, monotonic_usec]);
let _ = sd_notify::notify(true, &[sd_notify::NotifyState::Status("Reloading ...")]);
}