Recover shutdown with damaged templates and MySQL state

This commit is contained in:
Дмитрий committed 2026-10-14 07:07:35 +05:00
1 parent 482bbfcdfd
commit 4a9760b864
8 files changed
+168 -12

No files matched your search

+9 -6
View File
@@ -289,15 +289,18 @@ fn service(root: &Path, name: &'static str, exe: PathBuf, port: u16, listen: &[(
}
fn service_with(root: &Path, name: &'static str, exe: PathBuf, alternatives: &[PathBuf], port: u16, listen: &[(u16, u32)]) -> ServiceStatus {
// Prefer the repack's own record when it still matches a live process; otherwise discover by exact exe path.
// Prefer the exact installed executable owning the port; otherwise use a valid record or path discovery.
let norm = |p: &Path| p.to_string_lossy().replace('/', "\\");
let expected: Vec<String> = std::iter::once(&exe).chain(alternatives).map(|p| norm(p)).collect();
let proc = read_state_record(root, name)
.filter(is_alive)
.filter(|r| expected.iter().any(|e| r.exe.eq_ignore_ascii_case(e)))
.or_else(|| std::iter::once(&exe).chain(alternatives).find_map(|p| find_by_exe(p).into_iter().next()));
let owner = listen.iter().find(|(p, _)| *p == port).map(|(_, pid)| *pid);
// MySQL can launch a supervisor and a server with the same executable. The
// listening process is authoritative when its exact installation path matches.
let proc = owner.and_then(identity)
.filter(|record| expected.iter().any(|exe| record.exe.eq_ignore_ascii_case(exe)))
.or_else(|| read_state_record(root, name)
.filter(is_alive)
.filter(|r| expected.iter().any(|e| r.exe.eq_ignore_ascii_case(e))))
.or_else(|| std::iter::once(&exe).chain(alternatives).find_map(|p| find_by_exe(p).into_iter().next()));
let (state, port_ready, conflict) = match (&proc, owner) {
(Some(p), Some(o)) if p.pid == o => (ServiceState::Running, true, None),
(Some(_), _) => (ServiceState::Starting, false, None),