From fd6910558e17a39e5a6b76964af49f0a2f92825c Mon Sep 17 00:00:00 2001 From: Ginger Date: Wed, 24 Sep 2025 08:51:39 -0400 Subject: [PATCH] feat: Send notifications to systemd when a reload is triggered --- Cargo.lock | 1 + src/main/Cargo.toml | 1 + src/router/Cargo.toml | 1 - src/router/run.rs | 4 ++-- src/service/Cargo.toml | 7 +++++++ src/service/config/mod.rs | 9 ++++++--- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b4b762c..b67db33d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1121,6 +1121,7 @@ dependencies = [ "reqwest", "ruma", "rustyline-async", + "sd-notify", "serde", "serde_json", "serde_yml", diff --git a/src/main/Cargo.toml b/src/main/Cargo.toml index 8031e068..a2db05ce 100644 --- a/src/main/Cargo.toml +++ b/src/main/Cargo.toml @@ -156,6 +156,7 @@ sentry_telemetry = [ ] systemd = [ "conduwuit-router/systemd", + "conduwuit-service/systemd" ] journald = [ # This is a stub on non-unix platforms "dep:tracing-journald", diff --git a/src/router/Cargo.toml b/src/router/Cargo.toml index 9545c480..45978ead 100644 --- a/src/router/Cargo.toml +++ b/src/router/Cargo.toml @@ -40,7 +40,6 @@ io_uring = [ "conduwuit-admin/io_uring", "conduwuit-api/io_uring", "conduwuit-service/io_uring", - "conduwuit-api/io_uring", ] jemalloc = [ "conduwuit-admin/jemalloc", diff --git a/src/router/run.rs b/src/router/run.rs index ff54594f..f4884d51 100644 --- a/src/router/run.rs +++ b/src/router/run.rs @@ -65,7 +65,7 @@ pub(crate) async fn start(server: Arc) -> Result> { let services = Services::build(server).await?.start().await?; #[cfg(all(feature = "systemd", target_os = "linux"))] - sd_notify::notify(true, &[sd_notify::NotifyState::Ready]) + sd_notify::notify(false, &[sd_notify::NotifyState::Ready]) .expect("failed to notify systemd of ready state"); debug!("Started"); @@ -78,7 +78,7 @@ pub(crate) async fn stop(services: Arc) -> Result<()> { debug!("Shutting down..."); #[cfg(all(feature = "systemd", target_os = "linux"))] - sd_notify::notify(true, &[sd_notify::NotifyState::Stopping]) + sd_notify::notify(false, &[sd_notify::NotifyState::Stopping]) .expect("failed to notify systemd of stopping state"); // Wait for all completions before dropping or we'll lose them to the module diff --git a/src/service/Cargo.toml b/src/service/Cargo.toml index 517c4c5c..063b4582 100644 --- a/src/service/Cargo.toml +++ b/src/service/Cargo.toml @@ -67,6 +67,9 @@ release_max_log_level = [ "tracing/max_level_trace", "tracing/release_max_level_info", ] +systemd = [ + "dep:sd-notify", +] url_preview = [ "dep:image", "dep:webpage", @@ -119,5 +122,9 @@ blurhash.optional = true recaptcha-verify = { version = "0.1.5", default-features = false } ctor.workspace = true +[target.'cfg(all(unix, target_os = "linux"))'.dependencies] +sd-notify.workspace = true +sd-notify.optional = true + [lints] workspace = true diff --git a/src/service/config/mod.rs b/src/service/config/mod.rs index fd0d8764..414c22b6 100644 --- a/src/service/config/mod.rs +++ b/src/service/config/mod.rs @@ -45,13 +45,16 @@ impl Deref for Service { fn handle_reload(&self) -> Result { if self.server.config.config_reload_signal { #[cfg(all(feature = "systemd", target_os = "linux"))] - sd_notify::notify(true, &[sd_notify::NotifyState::Reloading]) - .expect("failed to notify systemd of reloading state"); + sd_notify::notify(false, &[ + sd_notify::NotifyState::Reloading, + sd_notify::NotifyState::monotonic_usec_now().expect("Failed to read monotonic time"), + ]) + .expect("failed to notify systemd of reloading state"); self.reload(iter::empty())?; #[cfg(all(feature = "systemd", target_os = "linux"))] - sd_notify::notify(true, &[sd_notify::NotifyState::Ready]) + sd_notify::notify(false, &[sd_notify::NotifyState::Ready]) .expect("failed to notify systemd of ready state"); }