diff --git a/src/main.rs b/src/main.rs index baab7fa..b5256cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,7 +127,7 @@ fn main() -> anyhow::Result<()> { service.add_profile_fragment(&mode)?; if !no_restart { service.reload_unit_config()?; - service.action("restart")?; + service.action("restart", false)?; } else { log::warn!("Profiling config will only be applied when systemd config is reloaded, and service restarted"); } @@ -138,7 +138,7 @@ fn main() -> anyhow::Result<()> { no_restart, }) => { let service = systemd::Service::new(&service); - service.action("stop")?; + service.action("stop", true)?; service.remove_profile_fragment()?; let resolved_opts = service.profiling_result()?; log::info!( @@ -154,7 +154,7 @@ fn main() -> anyhow::Result<()> { } service.reload_unit_config()?; if !no_restart { - service.action("start")?; + service.action("start", false)?; } } cl::Action::Service(cl::ServiceAction::Reset { service }) => { @@ -162,7 +162,7 @@ fn main() -> anyhow::Result<()> { let _ = service.remove_profile_fragment(); let _ = service.remove_hardening_fragment(); service.reload_unit_config()?; - service.action("try-restart")?; + service.action("try-restart", false)?; } } diff --git a/src/systemd/service.rs b/src/systemd/service.rs index ee344fd..21f0a48 100644 --- a/src/systemd/service.rs +++ b/src/systemd/service.rs @@ -197,11 +197,15 @@ impl Service { Ok(()) } - pub fn action(&self, verb: &str) -> anyhow::Result<()> { - log::info!("{} {}", verb, &self.unit_name()); - let status = Command::new("systemctl") - .args([verb, &self.unit_name()]) - .status()?; + pub fn action(&self, verb: &str, block: bool) -> anyhow::Result<()> { + let unit_name = self.unit_name(); + log::info!("{} {}", verb, unit_name); + let mut cmd = vec![verb]; + if !block { + cmd.push("--no-block"); + } + cmd.push(&unit_name); + let status = Command::new("systemctl").args(cmd).status()?; if !status.success() { anyhow::bail!("systemctl failed: {status}"); }