79452771

Date: 2025-02-19 21:06:45
Score: 2.5
Natty:
Report link

I didn't see a correct response on this. The answer is at the bottom of this page in the docs. here

Run pm2 with this flag

pm2 start app.js --shutdown-with-message

and add a check for 'message' instead of or aswell as SIGINT

    process.on('message', async (msg) => {
        if(msg === 'shutdown'){
            console.log( 'Shutting down...');
            await shutdownHandler();
            console.log('Exiting now...');

            setTimeout(function() {
                process.exit(0)
              }, 1500)
        }
    })

This works on windows, not so sure why the timeout is there just yet I included it because the docs do but my function is async so im thinking the timeout is useless, does anyone else this it is useless in the above scenario ? maybe it just gives the app time to process.exit gracefully.

now

pm2 stop app.js 

will run the shutdown procedure, to check logs (check shutdown has ran)

pm2 logs app.js

Hope this helps.

Reasons:
  • Whitelisted phrase (-1): Hope this helps
  • RegEx Blacklisted phrase (3): does anyone else
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: jxkeorton