Why is foreman gem ignoring the PORT environment variable?

落花浮王杯 提交于 2019-12-04 11:26:50

问题


I want the foreman gem to use the PORT value provided in the my development env file instead of using its own values. My files setup is shown below:

  1. A bash script to start foreman:

    foreman start -e development.env

  2. The development.env file content:

    PORT=3000

  3. The Procfile content

    web: bundle exec rails server thin -p $PORT -e $RAILS_ENV $1

The dev server ends up starting on port 5000. I know I can start foreman with --p 3000 to force it to use that port. But that defeats the purpose of the env file.

Any suggestions?


回答1:


Looking at the code: https://github.com/ddollar/foreman/blob/master/lib/foreman/process.rb it looks foreman will only take the PORT as a command line argument.




回答2:


I know this is an old post but it took me a while to figure out so might as well add a note here.

Foreman increments the PORT based on where your define the service in the Procfile.

Say our PORT environment variable is set to 3000.

In our first Procfile example Puma will run on PORT 3000:

web: bundle exec puma -q -p $PORT
worker: bundle exec rake jobs:work

But in our second Procfile it will run on PORT 3100 as the PORT variable is used on the second line.

worker: bundle exec rake jobs:work
web: bundle exec puma -q -p $PORT

Not sure why, I guess to prevent different processes from trying to take the same PORT.



来源:https://stackoverflow.com/questions/9804184/why-is-foreman-gem-ignoring-the-port-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!