Pm2: What's the difference between **reload** and **gracefulReload**?

Created on 16 Mar 2016  路  4Comments  路  Source: Unitech/pm2

Hi, I was wondering why there are 2 commands for reloading. For my server I have a shutdown function to wait for all connections to close:

const server = http.createServer(reqListener)
server.listen()

function shutdown () {
  server.close(() => {
    console.log('server closed')
    process.exit()
  })
}

The cluster mode docs say that I should listen for a shutdown message:

process.on('message', msg => {
  if (msg === 'shutdown') {
    shutdown()
  }
})

and then exec $ pm2 gracefulReload app in the console.

But I can also listen for SIGINT process.on('SIGINT', shutdown) and then do $ pm2 reload app in the console.

As far as I can tell both approaches do the same thing. Am I missing some case covered by gracefulReload?

pm2 v1.0.2
node v4.4.0

Most helpful comment

Thanks for the clarification. It seems like the shutdown message covers just a single use case, while catching SIGINT covers all. I expect any cleanup code to be executed whenever the server shuts down, regardless if it's part of a reload or a stop. Is there any reason to use gracefulReload at all?

All 4 comments

Reload will fallback to restart after a specified delay (GRACEFUL_LISTEN_TIMEOUT see here). After this delay, it'll force the script to restart even if it hasn't finished to process leftovers.

If you want to know more, please take a look at the Reload code source.

I believe the problem here is the documentation. It suggests listening to SIGINT at the link http://pm2.keymetrics.io/docs/usage/signals-clean-restart for graceful reload but mentions process "shutdown" message here at http://pm2.keymetrics.io/docs/usage/pm2-doc-single-page. SIGINT is sent whenever app is stopped/restarted/deleted/reloaded/gracefulReloaded but shutdown message is only sent when doing graceful reload, which by default will wait for 8000ms before sending SIGINT to the process.

Thanks for the clarification. It seems like the shutdown message covers just a single use case, while catching SIGINT covers all. I expect any cleanup code to be executed whenever the server shuts down, regardless if it's part of a reload or a stop. Is there any reason to use gracefulReload at all?

Patch available on [email protected] (main):

$ npm install pm2 -g
$ pm2 update
Was this page helpful?
0 / 5 - 0 ratings

Related issues

shaunwarman picture shaunwarman  路  3Comments

FujiHaruka picture FujiHaruka  路  3Comments

chaos-git picture chaos-git  路  3Comments

ghost picture ghost  路  3Comments

getvega picture getvega  路  3Comments