use tracing::{debug, warn};
pub fn notify_ready() {
#[cfg(target_os = "linux")]
{
match sd_notify::notify(false, &[sd_notify::NotifyState::Ready]) {
Ok(()) => debug!("sd_notify READY=1 sent"),
Err(e) => warn!(error = %e, "sd_notify READY=1 failed"),
}
}
#[cfg(not(target_os = "linux"))]
{
debug!("sd_notify not supported on this platform; notify_ready is a no-op");
}
}
pub fn notify_status(msg: &str) {
#[cfg(target_os = "linux")]
{
match sd_notify::notify(false, &[sd_notify::NotifyState::Status(msg)]) {
Ok(()) => debug!(status = msg, "sd_notify STATUS sent"),
Err(e) => warn!(error = %e, status = msg, "sd_notify STATUS failed"),
}
}
#[cfg(not(target_os = "linux"))]
{
let _ = msg;
debug!("sd_notify not supported on this platform; notify_status is a no-op");
}
}
pub fn notify_stopping() {
#[cfg(target_os = "linux")]
{
match sd_notify::notify(false, &[sd_notify::NotifyState::Stopping]) {
Ok(()) => debug!("sd_notify STOPPING=1 sent"),
Err(e) => warn!(error = %e, "sd_notify STOPPING=1 failed"),
}
}
#[cfg(not(target_os = "linux"))]
{
debug!("sd_notify not supported on this platform; notify_stopping is a no-op");
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn notify_ready_is_infallible() {
notify_ready();
}
#[test]
fn notify_status_is_infallible() {
notify_status("starting test harness");
notify_status("");
notify_status("ready (1 node)");
}
#[test]
fn notify_stopping_is_infallible() {
notify_stopping();
}
}