#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StartSteps {
pub shutdown_first: bool,
pub spawn: bool,
}
impl StartSteps {
const SATISFIED: Self = Self {
shutdown_first: false,
spawn: false,
};
}
pub fn start_steps(running: bool, stale: bool) -> StartSteps {
match (running, stale) {
(true, false) => StartSteps::SATISFIED,
(true, true) => StartSteps {
shutdown_first: true,
spawn: true,
},
(false, _) => StartSteps {
shutdown_first: false,
spawn: true,
},
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StopFallback {
Signal(u32),
Propagate,
}
pub fn stop_fallback(recorded_pid: Option<u32>) -> StopFallback {
match recorded_pid {
Some(pid) => StopFallback::Signal(pid),
None => StopFallback::Propagate,
}
}
pub fn stop_outcome(was_running: bool, stopped: bool) -> Result<&'static str, &'static str> {
match (was_running, stopped) {
(false, _) => Ok("daemon not running"),
(true, true) => Ok("daemon stopped"),
(true, false) => Err("the leviath daemon did not shut down within 5s"),
}
}
pub fn status_lines(running: bool, agents: usize, supervision: Option<String>) -> Vec<String> {
let mut lines = vec![crate::commands::daemon::format_status(running, agents)];
lines.extend(supervision);
lines
}
#[cfg(test)]
mod tests;