Skip to content

Commit

Permalink
add more systemd notify integration with stopping/reloading/ready states
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <[email protected]>
  • Loading branch information
girlbossceo committed Feb 5, 2025
1 parent babf828 commit 6215ee6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/core/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ impl Server {
return Err!("Reloading not enabled");
}

#[cfg(all(feature = "systemd", target_os = "linux"))]
sd_notify::notify(true, &[sd_notify::NotifyState::Reloading])
.expect("failed to notify systemd of reloading state");

if self.reloading.swap(true, Ordering::AcqRel) {
return Err!("Reloading already in progress");
}
Expand All @@ -83,7 +87,7 @@ impl Server {
})
}

pub fn restart(&self) -> Result<()> {
pub fn restart(&self) -> Result {
if self.restarting.swap(true, Ordering::AcqRel) {
return Err!("Restart already in progress");
}
Expand All @@ -93,7 +97,11 @@ impl Server {
})
}

pub fn shutdown(&self) -> Result<()> {
pub fn shutdown(&self) -> Result {
#[cfg(all(feature = "systemd", target_os = "linux"))]
sd_notify::notify(true, &[sd_notify::NotifyState::Stopping])
.expect("failed to notify systemd of stopping state");

if self.stopping.swap(true, Ordering::AcqRel) {
return Err!("Shutdown already in progress");
}
Expand Down
4 changes: 0 additions & 4 deletions src/router/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ pub(crate) async fn stop(services: Arc<Services>) -> Result<()> {
);
}

#[cfg(all(feature = "systemd", target_os = "linux"))]
sd_notify::notify(true, &[sd_notify::NotifyState::Stopping])
.expect("failed to notify systemd of stopping state");

info!("Shutdown complete.");
Ok(())
}
Expand Down
8 changes: 8 additions & 0 deletions src/service/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ impl Deref for Service {
#[implement(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");

self.reload(iter::empty())?;

#[cfg(all(feature = "systemd", target_os = "linux"))]
sd_notify::notify(true, &[sd_notify::NotifyState::Ready])
.expect("failed to notify systemd of ready state");
}

Ok(())
Expand Down

0 comments on commit 6215ee6

Please sign in to comment.