From af898378b9f7d2622dbe916e0f376955b91c14f8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 6 Oct 2022 10:04:07 +0200 Subject: [PATCH 1/2] use sd-notify to signal readyness Provide a way to signal nsncd has successfully started up, and is ready to accept connections. A more reliable way would be to only signal this once at least one worker has started up, but this is good enough (tm) for now. This can be used in a systemd.service file with Type=notify. --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + nsncd.service | 1 + src/main.rs | 4 +++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index f299e96..c2a1bf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,6 +446,7 @@ dependencies = [ "num-derive", "num-traits", "once_cell", + "sd-notify", "slog", "slog-async", "slog-term", @@ -647,6 +648,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +[[package]] +name = "sd-notify" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" + [[package]] name = "serde" version = "1.0.145" diff --git a/Cargo.toml b/Cargo.toml index 9756298..554ba20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ crossbeam-channel = "^0.5" nix = "^0.21.2" num-derive = "^0.3" num-traits = "^0.2" +sd-notify = "0.4.1" # Indirect dependency, constrained for MSRV once_cell = "~1.14" 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 From 9fa26c5298b7e5e255a0109efcb39d90368e3ae6 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Tue, 18 Oct 2022 11:29:51 -0400 Subject: [PATCH 2/2] Downgrade sd_notify to 0.3 for MSRV --- Cargo.lock | 4 ++-- Cargo.toml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c2a1bf4..6de3729 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -650,9 +650,9 @@ checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] name = "sd-notify" -version = "0.4.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "621e3680f3e07db4c9c2c3fb07c6223ab2fab2e54bd3c04c3ae037990f428c32" +checksum = "0cd08a21f852bd2fe42e3b2a6c76a0db6a95a5b5bd29c0521dd0b30fa1712ec8" [[package]] name = "serde" diff --git a/Cargo.toml b/Cargo.toml index 554ba20..3a5407a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,8 @@ crossbeam-channel = "^0.5" nix = "^0.21.2" num-derive = "^0.3" num-traits = "^0.2" -sd-notify = "0.4.1" +# Hold at 0.3: 0.4 MSRV is too new +sd-notify = "~0.3" # Indirect dependency, constrained for MSRV once_cell = "~1.14"