4 releases

0.1.2 May 6, 2022
0.1.1 Apr 12, 2022
0.1.0 Apr 12, 2022
0.0.1 Apr 12, 2022
Download history 86/week @ 2022-04-12 9/week @ 2022-04-19 29/week @ 2022-04-26 54/week @ 2022-05-03 68/week @ 2022-05-10

160 downloads per month

MIT/Apache

17KB
304 lines

systemctl

Small rust crate to interact with systemd units

crates.io License License crates.io
Rust crates.io

Unit / service operation

Nominal service operations:

use systemctl;
systemctl::stop("systemd-journald.service").unwrap();
systemctl::restart("systemd-journald.service").unwrap();

Service enumeration

use systemctl;
// list all units
systemctl::list_units(None, None);

// list all services 
// by adding a --type filter
systemctl::list_units(Some("service"), None);

// list all services currently `enabled` 
// by adding a --state filter
systemctl::list_units(Some("service"), Some("enabled"));

Unit structure

Use the unit structure for more information

let unit = systemctl::Unit::from_systemctl("sshd")
    .unwrap();
unit.restart().unwrap();
println!("active: {}", unit.active);
println!("preset: {}", unit.preset);
println!("auto_start (enabled): {}", unit.auto_start);
println!("config script : {}", unit.script);
println!("pid: {}", unit.pid);
println!("Running task(s): {}", unit.tasks.unwrap());
println!("Memory consumption: {}", unit.memory.unwrap());

TODO

  • parse all known attributes in from_systemctl
  • systemctl status seems to return an errorcode when service is "dead". We should find a correct condition on the error code, to permit stdout parsing / interpretation

Dependencies

~0.6–1MB
~23K SLoC