Skip to content

Commit

Permalink
Fix PM2 handling, at least for POSIX-compliant shells
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Aug 7, 2024
1 parent 4f79f92 commit 20a3228
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions run-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down

0 comments on commit 20a3228

Please sign in to comment.