diff --git a/Cargo.lock b/Cargo.lock index 5bbc2ac..c09d7d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,7 @@ dependencies = [ "nix", "num-derive", "num-traits", + "sd-notify", "slog", "slog-async", "slog-term", @@ -544,6 +545,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "sd-notify" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" + [[package]] name = "semver" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index d9f6ec4..0eda54c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ crossbeam-channel = "^0.5" nix = "^0.21.2" num-derive = "^0.3" num-traits = "^0.2" +sd-notify = "0.4.1" [dev-dependencies] criterion = "^0.3" diff --git a/nsncd.service b/nsncd.service index 7f6c3d0..99af01d 100644 --- a/nsncd.service +++ b/nsncd.service @@ -18,6 +18,7 @@ Description=name-service non-caching daemon [Service] ExecStart=/usr/lib/nsncd Restart=always +Type=notify [Install] WantedBy=multi-user.target diff --git a/src/main.rs b/src/main.rs index a1d7c3a..76e4a8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ use std::time::Duration; use anyhow::{Context, Result}; use crossbeam_channel as channel; +use sd_notify::NotifyState; use slog::{debug, error, o, Drain}; mod ffi; @@ -83,7 +84,6 @@ fn main() -> Result<()> { "worker_count" => worker_count, "handoff_timeout" => ?handoff_timeout, ); - let mut wg = WorkGroup::new(); let tx = spawn_workers(&mut wg, &logger, worker_count); @@ -93,6 +93,8 @@ fn main() -> Result<()> { std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o777))?; spawn_acceptor(&mut wg, &logger, listener, tx, handoff_timeout); + let _ = sd_notify::notify(true, &[NotifyState::Ready]); + let (result, handles) = wg.run(); if let Err(e) = result { // if a thread unwound with a panic, just start panicing here. the nss