diff --git a/src/os/mod.rs b/src/os/mod.rs index 614a646..9f9bfae 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -39,3 +39,37 @@ pub fn kill_gracefully(pid: u32) -> bool { "gracefully killing Minecraft server process not implemented on non-Unix platforms" ); } + +/// Freeze process. +/// Results in undefined behavior if PID is invaild. +/// +/// # Panics +/// Panics on platforms other than Unix. +#[allow(unreachable_code)] +pub fn freeze(pid: u32) -> bool { + #[cfg(unix)] + unsafe { + return unix::freeze(pid); + } + + unimplemented!( + "Freezing the Minecraft server process is not implemented on non-Unix platforms." + ); +} + +/// Unfreeze process. +/// Results in undefined behavior if PID is invaild. +/// +/// # Panics +/// Panics on platforms other than Unix. +#[allow(unreachable_code)] +pub fn unfreeze(pid: u32) -> bool { + #[cfg(unix)] + unsafe { + return unix::unfreeze(pid); + } + + unimplemented!( + "Unfreezing the Minecraft server process is not implemented on non-Unix platforms." + ); +} diff --git a/src/server.rs b/src/server.rs index 7d852c1..c0b67bf 100644 --- a/src/server.rs +++ b/src/server.rs @@ -218,7 +218,10 @@ impl Server { } // Spawn server in new task - Self::spawn_server_task(config, server); + // TODO uncomment this and add config option + //Self::spawn_server_task(config, server); + // TODO actual error handling + os::unfreeze((*server.pid.lock().await).unwrap()); true } @@ -587,9 +590,13 @@ async fn stop_server_signal(config: &Config, server: &Server) -> bool { }; // Send kill signal - if !crate::os::kill_gracefully(pid) { + // TODO uncomment this and add a config option + /*if !crate::os::kill_gracefully(pid) { error!(target: "lazymc", "Failed to send stop signal to server process"); return false; + }*/ + if !os::freeze(pid) { + error!(target: "lazymc", "Failed to send freeze signal to server process."); } // Update from starting/started to stopping