Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pm2 --update-env option seems not working

Tags:

node.js

pm2

I launched my node app by using ecosystem.config.js like this.

pm2 start ecosystem.config.js

And my ecosystem.config.js is here.

module.exports = {
  /**
  * Application configuration section
  * http://pm2.keymetrics.io/docs/usage/application-declaration/
  */
  apps : [
    // First application
    {
      name      : "API",
      script    : "./app/index.js",
      env: {
        COMMON_VARIABLE: "true"
      },
      env_production : {
        NODE_ENV: "production"
      }
    },
  ],

  /**
  * Deployment section
  * http://pm2.keymetrics.io/docs/usage/deployment/
  */
  deploy : {
    production : {
      user : "node",
      host : "212.83.163.1",
      ref  : "origin/master",
      repo : "[email protected]:repo.git",
      path : "/var/www/production",
      "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env production"
    },
    dev : {
      user : "node",
      host : "212.83.163.1",
      ref  : "origin/master",
      repo : "[email protected]:repo.git",
      path : "/var/www/development",
      "post-deploy" : "npm install && pm2 startOrRestart ecosystem.json --env dev",
      env  : {
        NODE_ENV: "dev"
      }
    }
  }
}

Then I tried to change the config file for watching mode on. I read this document so, I added watch: true attribute, then I tried pm2 restart ecosystem.config.js --update-env for applying changed config.

The app is restarted and attribute seems to be changed, because when I try pm2 list the watching is enabled. But my app is not restarted after change my code.

So, I just tried pm2 delete 0, pm2 start ecosystem.config.js then It's working well.

Why does --update-env options not working? What do I do wrong?

like image 895
hshan Avatar asked Jan 07 '17 03:01

hshan


2 Answers

pm2 restart <pid> --update-env worked for me as suggested in this answer

like image 190
Huzaifa Iftikhar Avatar answered Sep 28 '22 09:09

Huzaifa Iftikhar


The only reliable ways I've found to update a pm2 app config is either pm2 kill to stop the daemon, or pm2 delete <id|name> && pm2 start ecosystem.config.js for an individual app (as @hshan mentioned).

This issue claims it was fixed in 2014, but the comments there, plus the string of other questions/issues I found would seem to indicate otherwise: https://github.com/Unitech/pm2/issues/528

Update: Ongoing discussion here as well: https://github.com/Unitech/pm2/issues/3192

like image 43
Aaron Avatar answered Sep 28 '22 08:09

Aaron