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

Notify the service state through sd_notify #3903

Merged
merged 6 commits into from
Jan 29, 2025
Merged

Conversation

sandhose
Copy link
Member

This does mainly two things:

  • make the reloading logic part of the 'shutdown' (now named 'lifecycle') logic
  • advertise the various states of the application through sd_notify, including support for the watchdog

The API of the sd-notify crate is… weird. I was tempted to implement myself, but the fact that we need to be able to call clock_gettime with CLOCK_MONOTONIC makes me prefer someone else having that unsafe code already written.

Fixes #3879

Copy link

cloudflare-workers-and-pages bot commented Jan 28, 2025

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: d57552c
Status: ✅  Deploy successful!
Preview URL: https://32c552c0.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-lifecycle-manager.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose requested a review from reivilibre January 28, 2025 13:47
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

SGTM otherwise, with the caveat that it'd be good to check all the logic works in practice if you haven't already

@@ -32,6 +33,7 @@ rand.workspace = true
rand_chacha = "0.3.1"
reqwest.workspace = true
rustls.workspace = true
sd-notify = "0.4.5"
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be gated behind a flag, or is it cross-platform enough not to be a problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does use stuff from std::os::unix, which is 'Unix-only'. We don't claim to support Windows, so I'm happy keeping it like that

Comment on lines +66 to +69
if let Err(e) = sd_notify::notify(false, states) {
tracing::error!(
error = &e as &dyn std::error::Error,
"Failed to notify service manager"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this error expected if someone is not using systemd? If so, should we soften it somewhat so it doesn't sound like a major problem for them?

Maybe it would be good to elaborate in the comment what this is doing, I'm not sure most people would understand what this is for without having seen it before. (at least, I don't think knowledge about this is that common, but especially not amongst non-systemd users)

Copy link
Member Author

Choose a reason for hiding this comment

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

If NOTIFY_SOCKET is not set, it returns Ok(()) and is basically a no-op

@sandhose
Copy link
Member Author

Actually, tokio doesn't like that we create an interval with a zero duration… so it crashed if the watchdog environment variables were not set. Fixed that in d57552c

@sandhose sandhose enabled auto-merge January 29, 2025 13:58
@sandhose sandhose merged commit 69bbcfc into main Jan 29, 2025
21 checks passed
@sandhose sandhose deleted the quenting/lifecycle-manager branch January 29, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for systemd sd_notify
2 participants