Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Support for systemd notify
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schildt <[email protected]>
  • Loading branch information
SebastianSchildt authored and erikbosch committed Mar 5, 2024
1 parent 6936959 commit cfd068b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions kuksa_databroker/databroker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ futures = { version = "0.3.28", optional = true }
chrono = { version = "0.4.31", optional = true, features = ["std"] }
uuid = { version = "1.4.1", optional = true, features = ["v4"] }

# systemd related dependency, only relevant on linux systems
[target.'cfg(target_os = "linux")'.dependencies]
sd-notify = "0.4.1"

[features]
default = ["tls"]
tls = ["tonic/tls"]
Expand Down
18 changes: 18 additions & 0 deletions kuksa_databroker/databroker/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ where
{
let socket_addr = addr.into();
let listener = TcpListener::bind(socket_addr).await?;

/* On Linux systems try to notify daemon readiness to systemd.
* This function determines whether the a system is using systemd
* or not, so it is safe to use on non-systemd systems as well.
*/
#[cfg(target_os = "linux")]
{
match sd_notify::booted() {
Ok(true) => {
info!("Notifying systemd that the service is ready");
sd_notify::notify(false, &[sd_notify::NotifyState::Ready])?;
}
_ => {
debug!("System is not using systemd, will not try to notify");
}
}
}

serve_with_incoming_shutdown(
listener,
broker,
Expand Down

0 comments on commit cfd068b

Please sign in to comment.