summaryrefslogtreecommitdiffstats
path: root/src/service/systemd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/systemd.rs')
-rw-r--r--src/service/systemd.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/service/systemd.rs b/src/service/systemd.rs
index 2e3b74c..45f3bf9 100644
--- a/src/service/systemd.rs
+++ b/src/service/systemd.rs
@@ -2,7 +2,7 @@ use std::{fmt::Display, process::Command};
use serde::Deserialize;
-use crate::{Check, Error, Status};
+use crate::{Error, Status};
#[derive(Debug, Clone, Deserialize)]
pub struct Systemd {
@@ -16,18 +16,20 @@ impl Display for Systemd {
}
impl Systemd {
- pub async fn check(&self) -> Result<Check, Error> {
+ pub async fn check(&self) -> Result<Status, Error> {
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())
+ let status = match output.status.success() {
+ true => Status::Pass,
+ false => {
+ let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
+ Status::Fail(Some(format!("Service state: {}", stdout)))
+ }
+ };
+
+ Ok(status)
}
}