use crate::diag::{Diagnostic, SgCode};
pub fn supervisor_offline() -> Diagnostic {
Diagnostic::warn(
SgCode::SupervisorOffline,
"no supervisor is running; the state below was read from disk and is unsupervised",
)
.note("processes shown as running survived the supervisor and are now orphaned")
.help_cmd("resume supervision", "sysg start --daemonize")
.help_docs()
}
pub fn supervisor_not_responding() -> Diagnostic {
Diagnostic::warn(
SgCode::SupervisorNotResponding,
"the supervisor is running but did not answer its control socket in time",
)
.note("it may be shutting down or wedged; the reading below may be stale")
.help_cmd("force it down", "sysg stop --supervisor")
.help_docs()
}
pub fn state_inconsistent(detail: impl Into<String>) -> Diagnostic {
Diagnostic::warn(
SgCode::StatusStateInconsistent,
"recorded state disagrees with the live process table",
)
.note(detail)
.help_cmd("see what's running", "sysg status --live")
.help_docs()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn offline_is_sg0206_and_names_orphans() {
let diag = supervisor_offline();
assert_eq!(diag.code, SgCode::SupervisorOffline);
assert!(diag.render(false).contains("orphaned"));
}
#[test]
fn not_responding_is_sg0205() {
assert_eq!(
supervisor_not_responding().code,
SgCode::SupervisorNotResponding
);
}
#[test]
fn inconsistent_is_sg0009_and_carries_detail() {
let diag = state_inconsistent("web recorded running but pid 12 is gone");
assert_eq!(diag.code, SgCode::StatusStateInconsistent);
assert!(diag.render(false).contains("pid 12 is gone"));
}
}