diff options
| author | tv <tv@krebsco.de> | 2026-12-01 00:51:48 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 00:51:48 +0000 |
| commit | 54f070ef0f905f867a24dece72f667be23f9f843 (patch) | |
| tree | 6f6258ebfa3bb0532ad3abbbeefc5a550dc4d2cf /src/main.rs | |
| parent | 683e2128a5d00bcadea7cc2f71a48253032632a5 (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/main.rs')
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 4c1e24b..8d3830b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,13 @@ const OPTIONS: &[OptionSpec] = &[ Some("/etc/enstate/schema.json"), "The schema of the running generation; for --pack, one to check the source list against", ), + option( + "unit", + Kind::Text, + "UNIT", + None, + "The systemd unit that runs --migrate at boot and after switches: --apply starts it again if it failed", + ), OptionSpec { hidden: true, ..option( @@ -67,6 +74,7 @@ struct Settings { run_dir: Option<PathBuf>, schema: Option<PathBuf>, systemctl: Option<PathBuf>, + unit: Option<String>, } const COMMANDS: &[(&str, &str)] = &[ @@ -249,13 +257,22 @@ fn run() -> Result<ExitCode> { "plan" | "apply" | "stage" => { let submission = Submission::load(path.as_deref().unwrap())?; let planned = plan::plan(&schema, &store, &submission)?; - let plan = if command == "apply" { + let mut plan = if command == "apply" { planned.apply(&store, &schema_bytes, &systemctl, lock)? } else if command == "stage" { planned.stage(&store, &schema_bytes, lock)? } else { planned.plan }; + // A unit that failed for want of the state applied now (at boot, say) + // gets to serve the views, and is no longer failed. + if command == "apply" + && plan.accepted + && let Some(unit) = &settings.unit + && let Some(failed) = plan::start_if_failed(unit, &systemctl) + { + plan.failed.push(failed); + } if json { println!("{}", serde_json::to_string_pretty(&plan)?); } else { |
