Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const SYSTEMCTL_PATH: &str = "/usr/bin/systemctl";

use bon::Builder;

mod service_property;
pub use service_property::ServiceProperty;

/// Struct with API calls to systemctl.
///
/// Use the `::default()` impl if you don't need special arguments.
Expand Down Expand Up @@ -489,6 +492,21 @@ impl SystemCtl {
u.name = name.to_string();
Ok(u)
}

/// Show service property using systemctl show --property
pub fn show(&self, property: ServiceProperty, unit: &str) -> std::io::Result<Option<String>> {
let mut content =
self.systemctl_capture(["show", "--property", property.into(), "--value", unit])?;
if content.ends_with('\n') {
// remove line break at the end of the line, but keep other whitespaces
content.pop();
}
Ok(if content.as_str() != "[not set]" {
Some(content)
} else {
None
})
}
}

#[derive(Clone, Debug, Default, PartialEq)]
Expand Down
Loading