-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
Edit: I didn't realize I had already posted this a few weeks ago #3164. @vmarchaud you gave the same solution but the solution doesn't work. :(
What's going wrong?
I have my staging and production environments setup in my ecosystem.config.js. When I run the following, my environment is still stuck on staging instead of production.
pm2 start ecosystem.config.js --env staging
pm2 reload all --env production --update-env
How could we reproduce this issue?
Edit: Here is a cloneable repo to reproduce the issue
- Set app to print the
process.env.NODE_ENV
variable
server.js
console.log(process.env.NODE_ENV);
- Setup 2 environments in ecosystem.config.js
module.exports = {
apps: [
// First application
{
name: 'app',
script: 'server.js',
instances: 'max',
exec_mode: 'cluster',
error_file: 'err.log',
out_file: 'app.log',
merge_logs: false,
env: {
NODE_ENV: 'development',
},
env_staging: {
NODE_ENV: 'staging',
},
env_production: {
NODE_ENV: 'production',
},
},
],
};
- Start app in environment 1
./node_modules/.bin/pm2 start ecosystem.config.js --env staging
- Reload app in environment 2
./node_modules/.bin/pm2 reload all --env production --update-env
- Cat one of the app files
$ cat app-1.log
staging
staging
The second line should say production because the environment was updated.
Workaround
Once the process is already started on env X, to get it to start on env Y
-
Kill pm2 instances
./node_modules/.bin/pm2 stop all
-
Kill pm2 god daemon
pkill -9 PM2
-
Start pm2 in the correct environment
./node_modules/.bin/pm2 reload all --env production --update-env
Supporting information
===============================================================================
--- PM2 REPORT (Wed Oct 04 2017 12:42:48 GMT-0400 (EDT)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 2.7.0
node version : 8.4.0
node path : /Users/user/projects/app/tmp/../node_modules/.bin/pm2
argv : /Users/user/.nvm/versions/node/v8.4.0/bin/node,/Users/user/projects/app/node_modules/pm2/lib/Daemon.js
argv0 : node
user : user
uid : 692055800
gid : 1739585065
uptime : 1min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 2.7.0
node version : 8.4.0
node path : /Users/user/.nvm/versions/node/v8.4.0/bin/pm2
argv : /Users/user/.nvm/versions/node/v8.4.0/bin/node,/Users/user/.nvm/versions/node/v8.4.0/bin/pm2,report
argv0 : node
user : user
uid : 692055800
gid : 1739585065
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : darwin
type : Darwin
cpus : Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
cpus nb : 8
freemem : 70680576
totalmem : 17179869184
home : /Users/user
===============================================================================
--- PM2 list -----------------------------------------------
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ app │ 0 │ cluster │ 68381 │ online │ 1 │ 32s │ 0% │ 32.7 MB │ user │ disabled │
│ app │ 1 │ cluster │ 68382 │ online │ 1 │ 32s │ 0% │ 32.8 MB │ user │ disabled │
│ app │ 2 │ cluster │ 68418 │ online │ 1 │ 29s │ 0% │ 33.1 MB │ user │ disabled │
│ app │ 3 │ cluster │ 68419 │ online │ 1 │ 29s │ 0% │ 33.4 MB │ user │ disabled │
│ app │ 4 │ cluster │ 68455 │ online │ 1 │ 26s │ 0% │ 34.1 MB │ user │ disabled │
│ app │ 5 │ cluster │ 68456 │ online │ 1 │ 26s │ 0% │ 33.5 MB │ user │ disabled │
│ app │ 6 │ cluster │ 68492 │ online │ 1 │ 22s │ 0% │ 33.0 MB │ user │ disabled │
│ app │ 7 │ cluster │ 68493 │ online │ 1 │ 22s │ 0% │ 33.8 MB │ user │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/user/.pm2/pm2.log last 20 lines:
PM2 | 2017-10-04 12:42:25: Stopping app:app id:_old_4
PM2 | 2017-10-04 12:42:25: Stopping app:app id:_old_5
PM2 | 2017-10-04 12:42:25: App name:app id:_old_4 disconnected
PM2 | 2017-10-04 12:42:25: App [app] with id [_old_4] and pid [68012], exited with code [0] via signal [SIGINT]
PM2 | 2017-10-04 12:42:25: App name:app id:_old_5 disconnected
PM2 | 2017-10-04 12:42:25: App [app] with id [_old_5] and pid [68030], exited with code [0] via signal [SIGINT]
PM2 | 2017-10-04 12:42:25: pid=68012 msg=process killed
PM2 | 2017-10-04 12:42:25: Starting execution sequence in -cluster mode- for app name:app id:6
PM2 | 2017-10-04 12:42:25: pid=68030 msg=process killed
PM2 | 2017-10-04 12:42:25: Starting execution sequence in -cluster mode- for app name:app id:7
PM2 | 2017-10-04 12:42:26: App name:app id:6 online
PM2 | 2017-10-04 12:42:26: App name:app id:7 online
PM2 | 2017-10-04 12:42:29: Stopping app:app id:_old_6
PM2 | 2017-10-04 12:42:29: Stopping app:app id:_old_7
PM2 | 2017-10-04 12:42:29: App name:app id:_old_6 disconnected
PM2 | 2017-10-04 12:42:29: App [app] with id [_old_6] and pid [68048], exited with code [0] via signal [SIGINT]
PM2 | 2017-10-04 12:42:29: App name:app id:_old_7 disconnected
PM2 | 2017-10-04 12:42:29: App [app] with id [_old_7] and pid [68066], exited with code [0] via signal [SIGINT]
PM2 | 2017-10-04 12:42:29: pid=68048 msg=process killed
PM2 | 2017-10-04 12:42:29: pid=68066 msg=process killed
Please copy/paste the above report in your issue on https://github.com/Unitech/pm2/issues
IrosTheBeggar, Scott-Allen, DevBrent, bra1n, maksimoancha and 4 more