aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
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 {