From 20a32288ade3a203509ddee1dcb57363c15a8cc1 Mon Sep 17 00:00:00 2001 From: 00Fjongl <65314359+00Fjongl@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:56:05 -0500 Subject: [PATCH] Fix PM2 handling, at least for POSIX-compliant shells --- run-command.mjs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/run-command.mjs b/run-command.mjs index 62659fa5..38e0f36c 100644 --- a/run-command.mjs +++ b/run-command.mjs @@ -69,10 +69,10 @@ for (let i = 2; i < process.argv.length; i++) clearTimeout(timeoutId); if (response === "Error") throw new Error("Server is unresponsive."); } catch (e) { - console.error(e); + if (!(e instanceof TypeError)) console.error(e); await unlink(shutdown); } - if (config.production) + if (config.production && !process.argv.slice(i + 1).includes("kill")) exec("npm run pm2-stop", (error, stdout) => { if (error) throw error; console.log(stdout); @@ -99,12 +99,13 @@ for (let i = 2; i < process.argv.length; i++) break; } -// Forcibly kill all node processes and fully reset PM2. To be used for debugging. +// Kill all node processes and fully reset PM2. To be used for debugging. The +// npm run pm2-nuke is built into the command because, if handled in Node, it +// will not wait for PM2 to actually finish resetting before it closes itself. case "kill": - exec("npm run pm2-nuke", (error, stdout) => {console.log(stdout)}); if (process.platform === "win32") - exec("taskkill /F /IM node*", (error, stdout) => {console.log(stdout)}); - else exec("pkill node", (error, stdout) => {console.log(stdout)}); + exec("npm run pm2-nuke ; taskkill /F /IM node*", (error, stdout) => {console.log(stdout)}); + else exec("npm run pm2-nuke ; pkill node", (error, stdout) => {console.log(stdout)}); break; // No default case.