Add server start/stop timeout to force kill server if it gets stuck

This commit is contained in:
timvisee
2021-11-10 23:43:47 +01:00
parent 2026b6c846
commit 18fdf4c5f9
9 changed files with 125 additions and 9 deletions

View File

@@ -1,11 +1,27 @@
/// Force kill process on Unix by sending SIGKILL.
///
/// This is unsafe because the PID isn't checked.
pub unsafe fn force_kill(pid: u32) -> bool {
debug!(target: "lazymc", "Sending SIGKILL signal to {} to kill server", pid);
let result = libc::kill(pid as i32, libc::SIGKILL);
if result != 0 {
trace!(target: "lazymc", "SIGKILL failed: {}", result);
}
result == 0
}
/// Gracefully kill process on Unix by sending SIGTERM.
///
/// This is unsafe because the PID isn't checked.
pub unsafe fn kill_gracefully(pid: u32) {
pub unsafe fn kill_gracefully(pid: u32) -> bool {
debug!(target: "lazymc", "Sending SIGTERM signal to {} to kill server", pid);
let result = libc::kill(pid as i32, libc::SIGTERM);
trace!(target: "lazymc", "SIGTERM result: {}", result);
// TODO: send sigterm to childs as well?
// TODO: handle error if result != 0
if result != 0 {
trace!(target: "lazymc", "SIGTERM failed: {}", result);
}
result == 0
}