Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use sd-notify to signal readyness #35

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ crossbeam-channel = "^0.5"
nix = "^0.21.2"
num-derive = "^0.3"
num-traits = "^0.2"
# Hold at 0.3: 0.4 MSRV is too new
sd-notify = "~0.3"
# Indirect dependency, constrained for MSRV
once_cell = "~1.14"

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]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was curious about this but a) that's the example in the Rust crate and b) the C docs specifically say, "...it is generally recommended to ignore the return value of this call."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://docs.rs/sd-notify/latest/src/sd_notify/lib.rs.html#105

You don't want to fail if informing about readyness failed, e.g. if the service is /not/ run via systemd and/or the communication with the unix socket not possible.

See also https://gist.github.com/grawity/6e5980981dccf66f554bbebb8cd169fc.


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