{"action":"created","issue":{"url":"https://api.github.com/repos/Unitech/pm2/issues/3796","repository_url":"https://api.github.com/repos/Unitech/pm2","labels_url":"https://api.github.com/repos/Unitech/pm2/issues/3796/labels{/name}","comments_url":"https://api.github.com/repos/Unitech/pm2/issues/3796/comments","events_url":"https://api.github.com/repos/Unitech/pm2/issues/3796/events","html_url":"https://github.com/Unitech/pm2/issues/3796","id":340955056,"node_id":"MDU6SXNzdWUzNDA5NTUwNTY=","number":3796,"title":"--update-env behaviour is not intuitive","user":{"login":"awilkins","id":368399,"node_id":"MDQ6VXNlcjM2ODM5OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/368399?v=4","gravatar_id":"","url":"https://api.github.com/users/awilkins","html_url":"https://github.com/awilkins","followers_url":"https://api.github.com/users/awilkins/followers","following_url":"https://api.github.com/users/awilkins/following{/other_user}","gists_url":"https://api.github.com/users/awilkins/gists{/gist_id}","starred_url":"https://api.github.com/users/awilkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awilkins/subscriptions","organizations_url":"https://api.github.com/users/awilkins/orgs","repos_url":"https://api.github.com/users/awilkins/repos","events_url":"https://api.github.com/users/awilkins/events{/privacy}","received_events_url":"https://api.github.com/users/awilkins/received_events","type":"User","site_admin":false},"labels":[{"id":125446670,"node_id":"MDU6TGFiZWwxMjU0NDY2NzA=","url":"https://api.github.com/repos/Unitech/pm2/labels/S:%20In%20progress","name":"S: In progress","color":"9ddc80","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-13T09:51:56Z","updated_at":"2018-07-13T11:57:57Z","closed_at":null,"author_association":"NONE","body":"After a lot of frustration and experimentation, I have pinned down the quirks of `--update-env` that have been bugging me. These things are not clear from reading the documentation, but I also think it breaks the principle of least surprise and behaves counter to common sense.\r\n\r\n`pm2.json`\r\n```json\r\n{\r\n  \"apps\" : [{\r\n    \"name\"             : \"pm2-test\",\r\n    \"script\"           : \"index.js\",\r\n    \"env\": {\r\n      \"NODE_ENV\": \"default\",\r\n      \"VERB\": \"eats\",\r\n      \"NOUN\": \"apples\"\r\n    },\r\n    \"env_production\": {\r\n      \"NODE_ENV\": \"production\",\r\n      \"VERB\": \"hates\"\r\n    },\r\n    \"env_development\": {\r\n      \"NODE_ENV\": \"development\",\r\n      \"SESSION_STORAGE\": \"memory\"\r\n    }\r\n  }]\r\n}\r\n```\r\n\r\n`index.js` is a small node server that serves\r\n\r\n```javascript\r\n`Dave ${process.env.VERB} ${process.env.NOUN}!\\n`\r\n```\r\n\r\n## `--update-env` does not implicitly use the environment you started the app with\r\n\r\n```\r\npm2 start pm2.json --env production\r\ncurl http://localhost:3000\r\n> Dave hates apples!\r\n```\r\n\r\nHere we got env variables from both the default and environment section.\r\n\r\n```\r\n# Change default NOUN to \"anchovies\"\r\npm2 restart pm2.json\r\ncurl http://localhost:3000\r\n> Dave hates apples!  # as expected\r\npm2 restart pm2.json --update-env\r\n> Date eats anchovies! \r\n```\r\n\r\nI would expect `Dave hates anchovies!` here and I think many people would. \r\n\r\nI expected this to update the environment I started the app with, not to splat it with the default environment. Neither `restart` or `reload` mention the `--update-env` option in their cli `--help`. The documentation mentions this option but not how it interacts with additional environments.\r\n\r\n```\r\n# Remove NOUN from the file completely\r\npm2 restart pm2.json --update-env\r\n> Date eats anchovies!\r\n```\r\n\r\nThis too is a concern. Now my running app has an environment that can't be reproduced by copying the ecosystem file elsewhere. If I removed a variable like e.g. `DEBUG` from the file, debugging will still continue in my running application. This is not the only ticket to mention this issue, but it bears repeating."},"comment":{"url":"https://api.github.com/repos/Unitech/pm2/issues/comments/404812253","html_url":"https://github.com/Unitech/pm2/issues/3796#issuecomment-404812253","issue_url":"https://api.github.com/repos/Unitech/pm2/issues/3796","id":404812253,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNDgxMjI1Mw==","user":{"login":"awilkins","id":368399,"node_id":"MDQ6VXNlcjM2ODM5OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/368399?v=4","gravatar_id":"","url":"https://api.github.com/users/awilkins","html_url":"https://github.com/awilkins","followers_url":"https://api.github.com/users/awilkins/followers","following_url":"https://api.github.com/users/awilkins/following{/other_user}","gists_url":"https://api.github.com/users/awilkins/gists{/gist_id}","starred_url":"https://api.github.com/users/awilkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awilkins/subscriptions","organizations_url":"https://api.github.com/users/awilkins/orgs","repos_url":"https://api.github.com/users/awilkins/repos","events_url":"https://api.github.com/users/awilkins/events{/privacy}","received_events_url":"https://api.github.com/users/awilkins/received_events","type":"User","site_admin":false},"created_at":"2018-07-13T11:57:57Z","updated_at":"2018-07-13T11:57:57Z","author_association":"NONE","body":"Good question.\r\n\r\nI'm also not sure about inverting the behaviour in your highly used app ... while I feel the documentation both in the CLI and web could use some work, a change like that will no doubt surprise people who have learned these things the hard way.\r\n\r\nOr maybe you mean this `--keep-env` flag preserves the previous `--env` parameter, rather than preserving the whole environment?"}}
{"actor":{"display_login":"awilkins"}}