From a94e700b58896a0b0e3d240aeb25c07f3b774142 Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Thu, 28 Jan 2016 21:17:06 -0500 Subject: [PATCH] Make sure games have saved and exited before stopping the server. This should make the systemd version safe for production, though it can't yet deal with a game that hangs and doesn't exit. --- rlgwebd | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rlgwebd b/rlgwebd index 4142d68..422d886 100755 --- a/rlgwebd +++ b/rlgwebd @@ -279,6 +279,10 @@ TermSession.prototype.destroy = function () { gamemux.emit('end', this.gname, this.pname); delete sessions[tag]; tslog("Game %s ended.", tag); + /* Was that the last game? */ + if (!allowlogin && Object.keys(sessions).length == 0) { + shutdown(); + } }; function DglSession(filename) { @@ -1168,13 +1172,15 @@ function consoleHandler(chunk) { sessions[tag].close(); } progressWatcher.stdin.end("\n"); - setTimeout(shutdown, 2000); + if (Object.keys(sessions).length == 0) + setTimeout(shutdown, 500); + /* Otherwise wait for the games to end */ } } process.on("exit", function () { for (var tag in sessions) { - sessions[tag].term.kill('SIGHUP'); + sessions[tag].term.kill('SIGTERM'); } tslog("Quitting..."); return;