diff options
Diffstat (limited to 'src/plan.rs')
| -rw-r--r-- | src/plan.rs | 44 |
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() |
