use super::systemd::SYSTEMD_UNIT_PATTERN;
#[derive(Debug)]
pub(super) enum RestartStatus {
NotSystemd,
NoUnitsMatched,
Scheduled,
SpawnFailed(String),
}
impl RestartStatus {
pub(super) fn user_message(&self, current: &str, latest: &str) -> String {
match self {
RestartStatus::Scheduled => {
format!("Evolved from v{current} to v{latest}.")
}
RestartStatus::NotSystemd => format!(
"Evolved from v{current} to v{latest}. Binary updated on disk; restart \
the process / relaunch to load the new version."
),
RestartStatus::NoUnitsMatched => format!(
"Evolved from v{current} to v{latest}. Binary updated on disk, but no \
systemd units matched `{SYSTEMD_UNIT_PATTERN}` at system or user level \
— your daemon (if any) was not restarted. Restart it manually with \
`systemctl --user restart {SYSTEMD_UNIT_PATTERN}` (if installed as a \
user service) or `systemctl restart <your-unit>` (if a system service), \
or relaunch if running standalone."
),
RestartStatus::SpawnFailed(err) => format!(
"Evolved from v{current} to v{latest}. Binary updated on disk, but \
scheduling the systemd restart failed ({err}). Restart your daemon \
manually with `systemctl --user restart {SYSTEMD_UNIT_PATTERN}` \
(if a user service) or `systemctl restart {SYSTEMD_UNIT_PATTERN}` \
(if a system service)."
),
}
}
}