-1

Anyone know how I might use strong-pm to control a worker process, instead of a web app? I run the web app in the typical manner, via sl-pm, but I also want to run a worker process that is also part of the application. I want to deploy the web app to one docker container, and the worker process to another.

Essentially, how do I use strong-pm in a similar fashion as pm2, where you can specify the commands that you want pm2 to control?

Luke W
  • 8,276
  • 5
  • 44
  • 36

1 Answers1

0

Found a solution. Maybe will help someone else later.

slc run is what ultimately starts the node process on the server. according to slc run docs, it first looks in package.json for scripts.start and falls back to main section. So that was a dead end. I instead used an env var carefully placed in server.js to differentiate between the web app and my worker process. Something like process.env.START_WORKERS

# in server.js, within default loopback boot function
boot(app, __dirname, function(err) {
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module) {
    if (+process.env.START_WORKERS) {
      require('./workers/start');
      return;
    } else {
      app.start();
    }
  }
});
Luke W
  • 8,276
  • 5
  • 44
  • 36