Friday 25 September 2020

Startup Sequence of Nodejs Apps using PM2

I am using the command pm2 start apps.json to start multiple apps in a single command. These apps are defined in apps.json:

{
  "apps": [
    {
      "name": "foo",
      "script": "./foo.js",
    },
    {
      "name": "bar",
      "script": "./bar.js",
    },
    {
      "name": "baz",
      "script": "./baz.js",
    }
  ]
}

Question: Is it possible to define the startup sequence, such that foo.js has to finish starting first before bar.js and baz.js can start?

For example, foo.js can perform a graceful start, running process.send('ready') to change its pm2 status to online. Only then will bar.js and baz.js be started by pm2. This will be similar to Docker Compose's depend_on parameter.



from Startup Sequence of Nodejs Apps using PM2

No comments:

Post a Comment