aboutsummaryrefslogtreecommitdiffstats
path: root/src/plan.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 00:51:48 +0000
committertv <tv@krebsco.de>2026-12-01 00:51:48 +0000
commit54f070ef0f905f867a24dece72f667be23f9f843 (patch)
tree6f6258ebfa3bb0532ad3abbbeefc5a550dc4d2cf /src/plan.rs
parent683e2128a5d00bcadea7cc2f71a48253032632a5 (diff)
enstate: --apply starts the unit that runs --migrate again if it failed
The setting unit names it (the module: enstate.service). After a boot without state it failed; an accepted --apply starts it (--no-block, with the lock released), so it serves the views and is no longer failed.
Diffstat (limited to 'src/plan.rs')
-rw-r--r--src/plan.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/plan.rs b/src/plan.rs
index b37510d..12c91b6 100644
--- a/src/plan.rs
+++ b/src/plan.rs
@@ -592,3 +592,23 @@ pub fn react(reactions: &Reactions, systemctl: &Path, how: Reacting) -> Vec<Stri
}
failed
}
+
+/// Starts `unit` (the one that runs `--migrate`), without waiting for it, if it has
+/// failed; what failed in doing so.
+pub fn start_if_failed(unit: &str, systemctl: &Path) -> Option<String> {
+ let failed = Command::new(systemctl)
+ .args(["is-failed", "--quiet", unit])
+ .status()
+ .is_ok_and(|status| status.success());
+ if !failed {
+ return None;
+ }
+ match Command::new(systemctl)
+ .args(["start", "--no-block", unit])
+ .status()
+ {
+ Ok(status) if status.success() => None,
+ Ok(status) => Some(format!("{} start {unit}: {status}", systemctl.display())),
+ Err(error) => Some(format!("{} start {unit}: {error}", systemctl.display())),
+ }
+}