Make systemd unit start detect already running unit (#240)

* Make systemd unit start detect already running unit

* Prod CI

* Fixup messaging

* Reflect comments
This commit is contained in:
Ana Hobden 2023-02-10 12:43:46 -08:00 committed by GitHub
parent ab4c528595
commit fc13c1d250
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,12 +21,27 @@ impl StartSystemdUnit {
unit: impl AsRef<str>,
enable: bool,
) -> Result<StatefulAction<Self>, 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,
})
}
}