From fc13c1d25025d5201570835889baeceecc814df3 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 10 Feb 2023 12:43:46 -0800 Subject: [PATCH] Make systemd unit start detect already running unit (#240) * Make systemd unit start detect already running unit * Prod CI * Fixup messaging * Reflect comments --- src/action/linux/start_systemd_unit.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/action/linux/start_systemd_unit.rs b/src/action/linux/start_systemd_unit.rs index 37681d0..c59457a 100644 --- a/src/action/linux/start_systemd_unit.rs +++ b/src/action/linux/start_systemd_unit.rs @@ -21,12 +21,27 @@ impl StartSystemdUnit { unit: impl AsRef, enable: bool, ) -> Result, ActionError> { + let unit = unit.as_ref(); + let output = Command::new("systemctl") + .arg("is-active") + .arg(unit) + .output() + .await + .map_err(ActionError::Command)?; + + let state = if output.status.success() { + tracing::debug!("Starting systemd unit `{}` already complete", unit); + ActionState::Skipped + } else { + ActionState::Uncompleted + }; + Ok(StatefulAction { action: Self { - unit: unit.as_ref().to_string(), + unit: unit.to_string(), enable, }, - state: ActionState::Uncompleted, + state, }) } }