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