aboutsummaryrefslogtreecommitdiff
path: root/src/check.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/check.rs')
-rw-r--r--src/check.rs46
1 files changed, 13 insertions, 33 deletions
diff --git a/src/check.rs b/src/check.rs
index 42812c9..b0230e8 100644
--- a/src/check.rs
+++ b/src/check.rs
@@ -1,5 +1,5 @@
use crate::{log::update_service, Config, Status, GLOBAL_ERROR, STATUS};
-use anyhow::{anyhow, bail, Context, Result};
+use anyhow::{anyhow, bail, Result};
use chrono::Utc;
use futures::{stream::FuturesUnordered, StreamExt};
use log::info;
@@ -17,10 +17,10 @@ use crate::dbus::*;
pub enum Check {
Systemd(String),
SystemdGlobal,
-// SystemdUser {
-// user: String,
-// name: String,
-// },
+ SystemdUser {
+ user: String,
+ name: String,
+ },
SystemdUserGlobal(String),
Pacman(String),
Http {
@@ -83,38 +83,17 @@ impl Check {
output.status.exit_ok()?;
Ok(String::from_utf8(output.stdout)?)
}
- Check::Systemd(sname) => {
- let output = Command::new("systemctl")
- .arg("show")
- .arg("--no-pager")
- .arg(sname)
- .output()
- .await?;
- let output = String::from_utf8(output.stdout).context("systemctl output")?;
-
- let mut active = "";
- let mut sub = "";
- for line in output.split("\n") {
- if let Some((key, value)) = line.split_once("=") {
- match key {
- "ActiveState" => active = value,
- "SubState" => sub = value,
- _ => (),
- }
- }
- }
- let s = format!("{active} ({sub})");
- if active != "active" {
- Err(anyhow!(s))
- } else {
- Ok(s)
- }
+ Check::Systemd(name) => {
+ check_systemd_unit(None, name).await
}
Check::SystemdGlobal => {
check_systemd_all(None).await
}
- Check::SystemdUserGlobal(username) => {
- check_systemd_all(Some(username)).await
+ Check::SystemdUser { user, name } => {
+ check_systemd_unit(Some(user), name).await
+ }
+ Check::SystemdUserGlobal(user) => {
+ check_systemd_all(Some(user)).await
}
Check::Shell {
command, output, ..
@@ -168,6 +147,7 @@ impl Check {
Check::Shell { title, .. } => title.to_owned(),
Check::Pacman(_) => "Installed".to_string(),
Check::SystemdGlobal => "System Services".to_string(),
+ Check::SystemdUser { user, .. } => format!("User service for {user}"),
Check::SystemdUserGlobal(username) => format!("User services for {username}"),
}
}