Restructure SIGTERM signalling logic for Unix
This commit is contained in:
@@ -12,6 +12,7 @@ pub(crate) mod cli;
|
|||||||
pub(crate) mod config;
|
pub(crate) mod config;
|
||||||
pub(crate) mod mc;
|
pub(crate) mod mc;
|
||||||
pub(crate) mod monitor;
|
pub(crate) mod monitor;
|
||||||
|
pub(crate) mod os;
|
||||||
pub(crate) mod proto;
|
pub(crate) mod proto;
|
||||||
pub(crate) mod proxy;
|
pub(crate) mod proxy;
|
||||||
pub(crate) mod server;
|
pub(crate) mod server;
|
||||||
|
20
src/os/mod.rs
Normal file
20
src/os/mod.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#[cfg(unix)]
|
||||||
|
pub mod unix;
|
||||||
|
|
||||||
|
/// Gracefully kill process.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics on platforms other than Unix.
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
pub fn kill_gracefully(pid: u32) {
|
||||||
|
#[cfg(unix)]
|
||||||
|
unsafe {
|
||||||
|
unix::kill_gracefully(pid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unimplemented!(
|
||||||
|
"gracefully killing Minecraft server process not implemented on non-Unix platforms"
|
||||||
|
);
|
||||||
|
}
|
11
src/os/unix.rs
Normal file
11
src/os/unix.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/// Gracefully kill process on Unix by sending SIGTERM.
|
||||||
|
///
|
||||||
|
/// This is unsafe because the PID isn't checked.
|
||||||
|
pub unsafe fn kill_gracefully(pid: u32) {
|
||||||
|
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
|
||||||
|
}
|
@@ -64,7 +64,7 @@ impl ServerState {
|
|||||||
pub fn kill_server(&self) -> bool {
|
pub fn kill_server(&self) -> bool {
|
||||||
if let Some(pid) = *self.pid.lock().unwrap() {
|
if let Some(pid) = *self.pid.lock().unwrap() {
|
||||||
debug!(target: "lazymc", "Sending kill signal to server");
|
debug!(target: "lazymc", "Sending kill signal to server");
|
||||||
kill_gracefully(pid);
|
crate::os::unix::kill_gracefully(pid);
|
||||||
|
|
||||||
// TODO: should we set this?
|
// TODO: should we set this?
|
||||||
self.set_online(false);
|
self.set_online(false);
|
||||||
|
Reference in New Issue
Block a user