Mercurial > hg > rlgwebd
comparison rlgwebd @ 198:ea28353d620a
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.
author | John "Elwin" Edwards |
---|---|
date | Thu, 28 Jan 2016 21:17:06 -0500 |
parents | 3bdee6371c3f |
children | f3843245a35e |
comparison
equal
deleted
inserted
replaced
197:5041ec1fb426 | 198:ea28353d620a |
---|---|
277 } | 277 } |
278 this.emit('exit'); | 278 this.emit('exit'); |
279 gamemux.emit('end', this.gname, this.pname); | 279 gamemux.emit('end', this.gname, this.pname); |
280 delete sessions[tag]; | 280 delete sessions[tag]; |
281 tslog("Game %s ended.", tag); | 281 tslog("Game %s ended.", tag); |
282 /* Was that the last game? */ | |
283 if (!allowlogin && Object.keys(sessions).length == 0) { | |
284 shutdown(); | |
285 } | |
282 }; | 286 }; |
283 | 287 |
284 function DglSession(filename) { | 288 function DglSession(filename) { |
285 BaseGame.call(this); | 289 BaseGame.call(this); |
286 var pathcoms = filename.split('/'); | 290 var pathcoms = filename.split('/'); |
1166 tslog("Disconnecting..."); | 1170 tslog("Disconnecting..."); |
1167 for (var tag in sessions) { | 1171 for (var tag in sessions) { |
1168 sessions[tag].close(); | 1172 sessions[tag].close(); |
1169 } | 1173 } |
1170 progressWatcher.stdin.end("\n"); | 1174 progressWatcher.stdin.end("\n"); |
1171 setTimeout(shutdown, 2000); | 1175 if (Object.keys(sessions).length == 0) |
1176 setTimeout(shutdown, 500); | |
1177 /* Otherwise wait for the games to end */ | |
1172 } | 1178 } |
1173 } | 1179 } |
1174 | 1180 |
1175 process.on("exit", function () { | 1181 process.on("exit", function () { |
1176 for (var tag in sessions) { | 1182 for (var tag in sessions) { |
1177 sessions[tag].term.kill('SIGHUP'); | 1183 sessions[tag].term.kill('SIGTERM'); |
1178 } | 1184 } |
1179 tslog("Quitting..."); | 1185 tslog("Quitting..."); |
1180 return; | 1186 return; |
1181 }); | 1187 }); |
1182 | 1188 |