use std::{fmt::Display, process::Command}; use serde::Deserialize; use crate::{Check, Error, Status}; #[derive(Debug, Clone, Deserialize)] pub struct Systemd { pub service: String, } impl Display for Systemd { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}.service", self.service.trim_end_matches(".service")) } } impl Systemd { pub async fn check(&self) -> Result { let output = Command::new("systemctl") .arg("is-active") .arg(&self.service) .output()?; let stdout = String::from_utf8_lossy(&output.stdout).to_string(); Ok((!output.status.success()) .then(|| Check { status: Status::Fail, output: Some(format!("Service state: {}", stdout.trim())), }) .unwrap_or_default()) } }