understand node.js pm2 startup options
Asked Answered
P

1

5

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 (i.e. code changes are applied).

Is my assumption correct? How does startOrGracefulReload differ?

Phalanstery answered 30/10, 2015 at 14:51 Comment(0)
P
8

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.

Pimp answered 30/10, 2015 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.