pub struct SystemdUnit(/* private fields */);Expand description
The root of a systemd unit file
Implementations§
Source§impl SystemdUnit
impl SystemdUnit
Sourcepub fn get_section(&self, name: &str) -> Option<Section>
pub fn get_section(&self, name: &str) -> Option<Section>
Get a specific section by name
Sourcepub fn add_section(&mut self, name: &str)
pub fn add_section(&mut self, name: &str)
Add a new section to the unit file
Sourcepub fn syntax(&self) -> &SyntaxNode<Lang>
pub fn syntax(&self) -> &SyntaxNode<Lang>
Get the raw syntax node
Source§impl SystemdUnit
impl SystemdUnit
Sourcepub fn from_file_with_dropins(path: &Path) -> Result<Self, Error>
pub fn from_file_with_dropins(path: &Path) -> Result<Self, Error>
Load a unit file with drop-in configuration files merged
This loads the main unit file and then merges all .conf files from
the drop-in directory (<unit>.d/). Drop-in files are applied in
lexicographic order.
Drop-in directories are searched in the same directory as the unit file.
For example, if loading /etc/systemd/system/foo.service, this will
look for drop-ins in /etc/systemd/system/foo.service.d/*.conf.
§Example
// Loads foo.service and merges foo.service.d/*.conf
let unit = SystemdUnit::from_file_with_dropins(
Path::new("/etc/systemd/system/foo.service")
).unwrap();Sourcepub fn merge_dropin(&mut self, dropin: &SystemdUnit)
pub fn merge_dropin(&mut self, dropin: &SystemdUnit)
Merge a drop-in unit file into this unit
This applies the settings from a drop-in file to the current unit. According to systemd behavior:
- New sections are added
- Existing keys are replaced with values from the drop-in
- Multiple values for the same key (e.g.,
Wants=) are accumulated for directives that support accumulation
§Example
let mut main = SystemdUnit::from_str("[Unit]\nDescription=Main\n").unwrap();
let dropin = SystemdUnit::from_str("[Unit]\nAfter=network.target\n").unwrap();
main.merge_dropin(&dropin);
let section = main.get_section("Unit").unwrap();
assert_eq!(section.get("Description"), Some("Main".to_string()));
assert_eq!(section.get("After"), Some("network.target".to_string()));Trait Implementations§
Source§impl AstNode for SystemdUnit
impl AstNode for SystemdUnit
Source§impl Clone for SystemdUnit
impl Clone for SystemdUnit
Source§fn clone(&self) -> SystemdUnit
fn clone(&self) -> SystemdUnit
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SystemdUnit
impl Debug for SystemdUnit
Source§impl Display for SystemdUnit
impl Display for SystemdUnit
Source§impl FromStr for SystemdUnit
impl FromStr for SystemdUnit
Source§impl Hash for SystemdUnit
impl Hash for SystemdUnit
Source§impl PartialEq for SystemdUnit
impl PartialEq for SystemdUnit
impl Eq for SystemdUnit
impl StructuralPartialEq for SystemdUnit
Auto Trait Implementations§
impl Freeze for SystemdUnit
impl !RefUnwindSafe for SystemdUnit
impl !Send for SystemdUnit
impl !Sync for SystemdUnit
impl Unpin for SystemdUnit
impl !UnwindSafe for SystemdUnit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more