-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Reloading with a new environment and --update-env does not update the environment #3192
Comments
@vmarchaud is this a bug? |
I am seeing lots of environment issues as well with this version of PM2. It appears to be ignoring anything in the "env_" fields. |
Please read the docs here, its explained :
|
Thanks!, I found the docs shortly after writing this, but couldn't find my
thread. I was not expecting this update it looks like.
…--
[image: Giftnix]
Brandon Copley
Founder & CEO
t: 512.784.6060 <(512)%20784-6060>
e: copley.brandon@gmail.com
On Tue, Oct 10, 2017 at 3:37 PM, vmarchaud ***@***.***> wrote:
Closed #3192 <#3192>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3192 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABJShhySWz2wqYpkDvPZJuEcQCFRNR9wks5sq9WBgaJpZM4Ptu2k>
.
|
@vmarchaud Im not sure if I understand. If I launch the app in env X and I want to reload the app in env Y, using Do my reproduction steps make sense? |
@vmarchaud On step 4 in my original post, my command is equivalent to the one that you suggested from within the docs. Shouldn't this command reload pm2 in the correct environment with my above ecosystem config?
The top comment on the PM2 - Process File page in Disqus has a thread of people with the same issue. They suggest this command instead.
Edit: works fine now... how strange... Turns out that using
|
It seems But |
@vmarchaud judging by comments and votes it seems to be an issue. Do you mind reopening this ticket? |
Any updates on this issue? |
I will try to make some tests soon. |
Hi! Thanks for a quick reply! Unfortunately nope, We're trying to make deployment on our server, the directory structure is something like:
In the beginning I thought that the problem is in a symlink, but then I've changed the directory to |
Yay! I found this article and make it work! http://pm2.keymetrics.io/docs/tutorials/capistrano-like-deployments The key difference is that I had to explicitly set Thus,
works gracefully as expected! I'm sorry, it was my bad. Thanks for your attention! You're doing a great job! |
we have |
Try so many but this works |
I can't get any combination of the above suggestions to make The only way I can get |
@delino12 the |
@nitrocode you have to kill the server. addition to that, app will pickup the new changes when ever a server is restarted. Please make sure you restart or reload both the .env and the application files changes. |
@delino12 by server, do you mean the pm2 daemon, or a managed node process? I'm still trying to suss out whether this is a documentation bug, a widespread misunderstanding, or the |
@delino12 I tried both of these commands and they did not start the app in the intended environment
I tried replacing |
@nitrocode here is a quick step to handle env process
|
I don't understand the difference in commands between the ones you suggested and the ones I tried. I tried the same commands you suggested with the repo above with the same results. Do you get different results? |
Neither command works for me. I tried updating my pm2 installation, stopping all pm2 processes, killing all node process, then pm2 reload ecosystem.config.js && pm2 restart all --update-env --env production && pm2 logs It still starts with port 3011 instead of 3012. My code does read the 3011 port using process.env.PORT. |
The only way I managed to make it work was the command:
|
@viniwrubleski workaround works. Pure |
Its a bug.. Not working as explained in docs. and in my configuration file (process.json) I updated a variable -
to
but even after reloading value of that environment variable inside my code is printing the same. as previous. |
I am getting this behavior only when I set exec_mode: 'cluster', but if I am not using cluster mode, switching environments works fine. |
I'm still seeing this problem on my server. Is there any plan to fix the reload commands? |
I ran into this issue today. Updated the ecosystem file and ran a I'll try some of the suggestions in this thread, but one thing that is unclear from this issue is whether the team has confirmed there is a bug with having environment changes picked up, and if not, what the correct command is to force an app to be reloaded with environment changes. Is there a correct way to do this already, or if there's a bug, what is the recommended workaround? |
Still having this issue.
|
@vitalets - can you use the latest version and report your results? |
Worked with pm2 pm2 reload /srv/ecosystem.config.js --only my-app |
@vitalets - recently, I've noticed this behavior, but had not had the chance to confirm with multiple with/without tests. On behalf of myself and everyone else, Thank You! |
For me the only way to get this working(on version 3.5.0) is:
|
I'm on v3.5.1, with cluster mode, and the above command still doesn't work. |
Any update on this? As @srosset81 said, it doesn't work on 3.5.1 |
To ensure that both the system environment variables and the environment variables defined in ecosystem.json are updated, you will need to run two commands. This is very inconvenient and inconsistent. it working fork mode.run at jar program.pm2 version 3.5.1 現状、システムの環境変数とjsonで定義された2種類の環境変数を確実に更新するには二回コマンドを実行する必要があると思いますが、これはとても不便です。 |
After trying many of the above suggestions, not bringing some results, I found out that property mode: 'development' in my webpack.config.js file was that which defined the NODE_ENV variable, setting it always that value. That's why I couldn't update that variable via pm2, which used the bundle file of the built version (with Webpack) of my app. |
As already read on comments on this issue and related, seems that |
Can anybody suggest a deamon like PM2 that does not try to reinvent ENV VARS, something that has been working flawlessly since 1970? (edit - later I understood how ecosystem works and it makes sense :) comment was the heat of the moment ) |
So if you want to change an environment variable value, you need to use the ecosystem file, rather than just |
Use docker :) |
@v4.4.0 pm2 this is still not fixed. The issue should be reopened.
|
This worked for me.
Conclusion: Only use one of the two until |
pm2 restart all worked for me as i gave sudo priviliges i.e sudo su |
I am currently using the latest PM2. I barely got test env vars running but after I added production vars it does not want to update them at all. I tried all the possible methods but this just does not work. |
As of 2021 this is the only solution that worked for me; have to make it explicit the environment to run so that env vars get refreshed from file. |
Still having this issue as of v5.1.2 I use docker for everything that I can for a variety of reasons but I run a couple of services to do with my CI/CD pipeline that are easier to manage on bare metal due to OS interactions and the like. I like using .env files to manage my deployments (personal preference, standardised across most of my projects) and PM2 still doesn't seem to want to reload those vars with either My current workaround to avoid having to worry about dynamically calling processes by name to perform operations on them is to just run This way I can both target services manually or batch process updates / testing by killing all the services that need to be updated then running the |
Just for the history. Firstly, carefully read this documentation. https://pm2.io/docs/runtime/best-practices/environment-variables/ Secondly, it is not explicitly highlighted but you can not mixed approaches according to environment variable update and initial starting of pm2 command. There are only two regimes:
Other words, if you started pm2 with the command Note: the only one edge case when you can mix this two approaches is when you want to migrate between them gracefully. To do this, the only need to move all env vars from Ecosystem file to command like or vise versa from command line to Ecosystem file. |
What about variables that app itself reads from local .env files? |
I am also experiencing the same issue with 5.3.0 I loaded env variables from ecosystem.config.json; no matter what I try, it won't reload variables. |
Use |
One reason may also be like. suppose you have 2 repo. In first repo, there is a env file for example. In second repo, there is a env file for example. And you are starting repo-1 by pm2. So in the first repo, the env variable will be abcd and the credentials are mismatched. So make sure that both env variable are same. |
As of September 2024, this is still a problem. I found a bug with config extension, fixed it, and covered with tests. My use case was with |
After hours of trying, I found something interesting: For v5.4.3 ❌: not working
So let's wrap it up, for env to successfully change, you should:
|
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.
How could we reproduce this issue?
Edit: Here is a cloneable repo to reproduce the issue
process.env.NODE_ENV
variableserver.js
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
Kill pm2 god daemon
Start pm2 in the correct environment
Supporting information
The text was updated successfully, but these errors were encountered: