Abstract over sd_notify

This commit is contained in:
Lambda 2024-09-26 16:27:58 -07:00 committed by Charles Hall
parent 6ab87f97dd
commit 39880cc6ac
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
2 changed files with 30 additions and 9 deletions

View file

@ -5,7 +5,7 @@
use std::process::ExitCode;
use clap::Parser;
use tracing::error;
use tracing::{error, info};
mod api;
mod cli;
@ -41,6 +41,31 @@ fn version() -> String {
}
}
#[derive(Debug, Clone, Copy)]
enum ApplicationState {
Ready,
Stopping,
}
fn set_application_state(state: ApplicationState) {
info!(?state, "Application state changed");
#[cfg(feature = "systemd")]
{
use sd_notify::NotifyState;
fn notify(states: &[NotifyState<'_>]) {
sd_notify::notify(false, states)
.expect("should be able to notify systemd");
}
match state {
ApplicationState::Ready => notify(&[NotifyState::Ready]),
ApplicationState::Stopping => notify(&[NotifyState::Stopping]),
};
}
}
#[tokio::main]
async fn main() -> ExitCode {
let args = cli::Args::parse();