为什么foreman gem忽略了PORT环境变量?

[英]Why is foreman gem ignoring the PORT environment variable?


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:

我希望foreman gem使用我的开发环境文件中提供的PORT值,而不是使用自己的值。我的文件设置如下所示:

  1. A bash script to start foreman:

    启动工头的bash脚本:

    foreman start -e development.env

    工头开始-e development.env

  2. The development.env file content:

    development.env文件内容:

    PORT=3000

    PORT = 3000

  3. The Procfile content

    Procfile内容

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

    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.

开发服务器最终从端口5000开始。我知道我可以使用--p 3000启动工头强制它使用该端口。但这违背了env文件的目的。

Any suggestions?

有什么建议么?

2 个解决方案

#1


8  

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.

查看代码:https://github.com/ddollar/foreman/blob/master/lib/foreman/process.rb它看起来工头只会将PORT作为命令行参数。

#2


10  

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.

Foreman根据您在Procfile中定义服务的位置来增加PORT。

Say our PORT environment variable is set to 3000.

假设我们的PORT环境变量设置为3000。

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

在我们的第一个Procfile示例中,Puma将在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.

但是在我们的第二个Procfile中,它将在PORT 3100上运行,因为PORT变量用在第二行。

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.

不知道为什么,我想防止不同的进程尝试使用相同的PORT。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/03/21/2fc933fef01c7b44d54a40eeca68ed64.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号