简体   繁体   中英

understand node.js pm2 startup options

pm2 has the following command line options:

  startOrRestart <json>
  startOrReload <json>
  startOrGracefulReload <json>

but what are the differences between them?

As far as I understand all start the application(s) if they are not already started. So let's consider the application (an HTTP server) is curently running.

I assume restart forces an application to stop and restart it afterwards, and reload would stop accepting new connections, wait for all connections to be handled and then restarts the application. The difference would be that there is no downtime or aborted connections for reload, but apart from that it behaves just as restart (ie code changes are applied).

Is my assumption correct? How does startOrGracefulReload differ?

The three commands will start your application if it is not already running, so, let's concentrate what happen in the case that it is already running.

startOrRestart : It will stop all your application in the JSON file and then all of them will be started again. You will have downtime.

startOrReload : As you can read here :

As opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload.

So, the main difference is that you will have no downtime.

startOrGracefulReload : Again, you can read more here :

Sometimes you can experience a very long reload, or a reload that doesn't work (fallback to restart) meaning that your app still has open connections on exit. Or you may need to close all databases connections, clear a data queue or whatever.

To work around this problem you have to use the graceful reload.

So, basically pm2 asks your application to exit before reloading it just in case you have dependencies like database connections or pending requests. You will have to specify the time that your application needs in order to close all existing connections. Then, a new process will start and when this new process says " Hey! I am alive! ", then your old process will be ended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM