From 9683c4f41c588da2f4645ee5b5ca291fd3af7279 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sat, 12 Mar 2022 18:04:18 +0200 Subject: [PATCH] kill server child process on various signals --- scripts/minecraft.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/minecraft.js b/scripts/minecraft.js index e438c1c..86e6e77 100644 --- a/scripts/minecraft.js +++ b/scripts/minecraft.js @@ -403,11 +403,14 @@ function main() { const bridge = new Bridge(); bridge.start(); - process.on("beforeExit", () => { - if (bridge.process) { - console.log("server process: killing on parent exit"); + const onServerClosing = () => { + if (bridge.process) bridge.process.kill("SIGINT"); - } + process.exit(); + }; + + ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM'].forEach((eventType) => { + process.on(eventType, onServerClosing); }); }