Skip to content

Commit

Permalink
use sd-notify to signal readyness
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
flokli committed Oct 7, 2022
1 parent b714fde commit 67fd87c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions nsncd.service
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Description=name-service non-caching daemon
[Service]
ExecStart=/usr/lib/nsncd
Restart=always
Type=notify

[Install]
WantedBy=multi-user.target
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down

0 comments on commit 67fd87c

Please sign in to comment.