Implement config handling

This commit is contained in:
[object Object] 2022-12-30 13:17:04 -08:00
parent f02217abd3
commit 05dfd19d80
No known key found for this signature in database
GPG Key ID: F9ECDF22D7D28727
2 changed files with 31 additions and 28 deletions

View File

@ -33,6 +33,10 @@ directory = "."
# Warning: if using a bash script read: https://git.io/JMIKH # Warning: if using a bash script read: https://git.io/JMIKH
command = "java -Xmx1G -Xms1G -jar server.jar --nogui" command = "java -Xmx1G -Xms1G -jar server.jar --nogui"
# Freeze the server process instead of restarting it when no players online, making it start up faster.
# Only works on Unix (Linux or MacOS)
#freeze_process = true
# Immediately wake server when starting lazymc. # Immediately wake server when starting lazymc.
#wake_on_start = false #wake_on_start = false

View File

@ -217,10 +217,11 @@ impl Server {
None => info!(target: "lazymc", "Starting server..."), None => info!(target: "lazymc", "Starting server..."),
} }
// TODO add config option for this if config.server.freeze_process {
if let Some(pid) = *server.pid.lock().await { if let Some(pid) = *server.pid.lock().await {
return os::unfreeze(pid); return os::unfreeze(pid);
} }
}
// Spawn server in new task // Spawn server in new task
Self::spawn_server_task(config, server); Self::spawn_server_task(config, server);
@ -590,32 +591,30 @@ async fn stop_server_signal(config: &Config, server: &Server) -> bool {
} }
}; };
// Send kill signal if config.server.freeze_process {
// 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) { if !os::freeze(pid) {
error!(target: "lazymc", "Failed to send freeze signal to server process."); error!(target: "lazymc", "Failed to send freeze signal to server process.");
} }
// Update from starting/started to stopping
/* TODO uncomment this and add a config option
server
.update_state_from(Some(State::Starting), State::Stopping, config)
.await;
server
.update_state_from(Some(State::Started), State::Stopping, config)
.await;
*/
server server
.update_state_from(Some(State::Starting), State::Stopped, config) .update_state_from(Some(State::Starting), State::Stopped, config)
.await; .await;
server server
.update_state_from(Some(State::Started), State::Stopped, config) .update_state_from(Some(State::Started), State::Stopped, config)
.await; .await;
} else {
if !crate::os::kill_gracefully(pid) {
error!(target: "lazymc", "Failed to send stop signal to server process");
return false;
}
server
.update_state_from(Some(State::Starting), State::Stopping, config)
.await;
server
.update_state_from(Some(State::Started), State::Stopping, config)
.await;
}
true true
} }