Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASAP: PM2 environment variables are identical on two different instances although the variables must be different #3633

Closed
ibudisteanu opened this issue Apr 28, 2018 · 2 comments
Labels

Comments

@ibudisteanu
Copy link

ibudisteanu commented Apr 28, 2018

Hi,

For 4 hours I am struggling with pm2 and I encounter a bug. I wrote a script that opens multiple instances. Although all the instances have different environment variables, the apps receive the same identical environment variable namely the last one. Please kindly help me out because I need to deploy the pm2 on multiple xeon servers.

{
  "apps": [

    {
      "script": "npm",
      "name": "start8080",
      "args": "start",
      "env": {
        "SERVER_PORT": 8080,
        "INSTANCE_PREFIX": "8080",
        "NODE_ENV": "production"
      },
      "error_file": "logs/proj-8080.err.log",
      "out_file": "logs/proj-8080.out.log"
    },
    {
      "script": "npm",
      "name": "start80",
      "args": "start",
      "env": {
        "SERVER_PORT": 80,
        "INSTANCE_PREFIX": "80",
        "NODE_ENV": "production"
      },
      "error_file": "logs/proj-80.err.log",
      "out_file": "logs/proj-80.out.log"
    },

  ]
}

Both instances receive the last environment variable namely as value "80".

The data is passed to the application but only the last one. If I switch the apps between each other, and make the 8080 the last one, the apps receive the environment variable as "8080" on both instances.

I am using pm2 under Linux, Ubuntu 16.x, Debian

pm2 version 2.10.3

Thanks

@ibudisteanu ibudisteanu changed the title ASAP: PM2 environment variables are identical on two different instances although it must be different ASAP: PM2 environment variables are identical on two different instances although the variables must be different Apr 28, 2018
@ibudisteanu
Copy link
Author

I was able to make a trick to solve my problem, but still running the script has the same behavior as described above.

I was able to bypass the need of script by using the pm2 inline CLI

SERVER_PORT=80 INSTANCE_PREFIX=80 pm2 start  npm -- run start -- n=80 ;
pm2 restart npm --name "80" --update-env ;

SERVER_PORT=8080 INSTANCE_PREFIX=8080 pm2 start npm -- run start ;
pm2 restart npm --name "8080" --update-env ;

SERVER_PORT=8081 INSTANCE_PREFIX=8081 pm2 start npm -- run start ;
pm2 restart npm --name "8081" --update-env ;

SERVER_PORT=8082 INSTANCE_PREFIX=8082 pm2 start npm -- run start ;
pm2 restart npm --name "8082" --update-env ;

SERVER_PORT=8083 INSTANCE_PREFIX=8083 pm2 start npm -- run start ;
pm2 restart npm --name "8083" --update-env 

@stale
Copy link

stale bot commented May 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 24, 2020
@stale stale bot closed this as completed Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant