aboutsummaryrefslogtreecommitdiffstats
path: root/src/plan.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 13:13:44 +0000
committertv <tv@krebsco.de>2026-11-30 14:59:15 +0000
commitac214a023e3d823a8231c365656cfa27703f27d5 (patch)
tree551ca7e87e2dce128b23732d28100edd84861ffc /src/plan.rs
parenta0f22c88d54d351b060c2d0d9f0a8cbf5f412ba2 (diff)
enstate: reactions after applying, and after a switch
After applying, units are restarted or reloaded, and started if they aren't running: they may have failed for want of their views. That happens with the store's lock released: a unit restarted may want the one that runs --migrate, which waits for the lock. After a switch, --migrate runs from the unit that units using views are ordered after, so only running units react, without waiting for them (--no-block try-restart, try-reload-or-restart).
Diffstat (limited to 'src/plan.rs')
-rw-r--r--src/plan.rs44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/plan.rs b/src/plan.rs
index 80e2bad..8627dd8 100644
--- a/src/plan.rs
+++ b/src/plan.rs
@@ -21,7 +21,7 @@ use crate::name::Address;
use crate::program::{self, Given, ProgramFailed, Role};
use crate::schema::{Reactions, Schema};
use crate::scratch::Scratch;
-use crate::store::{Kept, Store};
+use crate::store::{Kept, Lock, Store};
use crate::submission::{Change, Item, Submission};
use crate::view::{self, FileChange};
@@ -469,8 +469,16 @@ fn apply_items(base: &Content, items: &[Item], excluded: &BTreeSet<usize>) -> Co
impl Planned {
/// Applies the plan, if it was accepted: the new snapshot, the views that change,
- /// and their reactions, by `systemctl`.
- pub fn apply(self, store: &Store, schema_bytes: &[u8], systemctl: &Path) -> Result<Plan> {
+ /// and, with `lock` released, their reactions. Units restarted may want the unit
+ /// that runs `--migrate`, which waits for the lock: holding it while they restart
+ /// would deadlock.
+ pub fn apply(
+ self,
+ store: &Store,
+ schema_bytes: &[u8],
+ systemctl: &Path,
+ lock: Lock,
+ ) -> Result<Plan> {
let mut plan = self.plan;
if !plan.accepted {
return Ok(plan);
@@ -491,22 +499,38 @@ impl Planned {
.with_context(|| format!("view {name}"))?;
}
}
- plan.failed = react(&plan.reactions, systemctl);
+ drop(lock);
+ plan.failed = react(&plan.reactions, systemctl, Reacting::Apply);
Ok(plan)
}
}
-/// Runs `reactions`; what failed.
-pub fn react(reactions: &Reactions, systemctl: &Path) -> Vec<String> {
+/// How reactions are run.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Reacting {
+ /// After applying a submission: units are restarted or reloaded, and started if
+ /// they aren't running (they may have failed for want of their views).
+ Apply,
+ /// After a generation change, from the unit that runs `--migrate`, which units
+ /// using views are ordered after: only units that are running, without waiting
+ /// for them (`--no-block`). A unit that isn't running starts with the views in
+ /// place.
+ Migrate,
+}
+
+/// Runs `reactions` by `systemctl`, each unit once; returns what failed.
+pub fn react(reactions: &Reactions, systemctl: &Path, how: Reacting) -> Vec<String> {
let mut failed = Vec::new();
- for (verb, units) in [
- ("restart", &reactions.restart),
- ("reload", &reactions.reload),
- ] {
+ let (options, restart, reload): (&[&str], _, _) = match how {
+ Reacting::Apply => (&[], "restart", "reload-or-restart"),
+ Reacting::Migrate => (&["--no-block"], "try-restart", "try-reload-or-restart"),
+ };
+ for (verb, units) in [(restart, &reactions.restart), (reload, &reactions.reload)] {
if units.is_empty() {
continue;
}
let result = Command::new(systemctl)
+ .args(options)
.arg(verb)
.args(units)
.status()