I want my script to not automatically restart if there was an error. To only restart if it exited gracefully with exit code 0.
I created ecosystem.config.js in the script's folder and filled it with:
module.exports = {
apps : [{
name : "My script",
script : "./index.js",
stop_exit_codes: [2]
}]
}
So that when I use process.exit(2), it should stop the automatic restart.
However, it does not work and the script restarts automatically when I put this at the top of my script.
console.log("test");
process.exit(2);
So I tried using --stop-exit-codes instead:
pm2 start index.js --stop-exit-codes 2
But pm2 gives me this error:
error: unknown option --stop-exit-codes
How can I get the stop exit codes feature of PM2 to work?
Doc: https://pm2.keymetrics.io/docs/usage/restart-strategies/
module.exports = {
script:'api.js',
max_memory_restart:'30m'
}