Foreman / Puma没有在开发环境中使用指定的端口 [英] Foreman/Puma isn't using the specified port in dev env

查看:105
本文介绍了Foreman / Puma没有在开发环境中使用指定的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的application.yml中设置端口为3000(figaro管理env变量)
rails s 使用端口3000
但是当我运行 foreman start (按照Heroku的建议)我得到以下输出

  14:53:23 web.1 |以pid开头24425 
14:53:23 web.1 | [24425] Puma以群集模式启动...
14:53:23 web.1 | [24425] *版本2.11.1(ruby 2.2.0-p0),代号:Intrepid Squirrel
14:53:23 web.1 | [24425] *最少线程数:5,最多线程数:5
14:53:23 web.1 | [24425] *环境:开发
14:53:23 web.1 | [24425] *流程工作者:2
14:53:23 web.1 | [24425] *预加载应用程序
14:53:24 web.1 |警告:跳过PORT键。已经在ENV中设置。
14:53:25 web.1 | [24425] *在tcp上收听://0.0.0.0:5000
14:53:25 web.1 | [24425]使用Ctrl-C停止
14:53:25 web.1 | [24425] - 工人0(pid:24426)启动,阶段:0
14:53:25 web.1 | [24425] - Worker 1(pid:24427)booted,phase:0

Procfile

  web:bundle exec puma -C config / puma.rb 

config / puma.rb

  workers Integer(ENV ['WEB_CONCURRENCY'] | | 2)
threads_count = Integer(ENV ['MAX_THREADS'] || 5)
线程threads_count,threads_count

preload_app!

rackup DefaultRackup
端口ENV ['PORT'] || 3000
环境ENV ['RACK_ENV'] || 'development'

on_worker_boot do
ActiveRecord :: Base.establish_connection
end

config / application.yml

  PORT:3000




  • Rails 4.2.0

  • 工头0.78.0

  • Ruby 2.2.0p0

  • 美洲狮2.11.1


解决方案

b $ b

然后你会发现端口神秘地设置为5000,即使它不在你的ENV中。



固定在底部。 p>

  puma_port = ENV ['PORT'] || 3000 
把 ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
把 puma_port是#{puma_port}
把ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

打印出来

  16:49:28 web.1 | ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
16:49:28 web.1 | puma_port is 5000
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

然后放置这条线在你的Procfile中(不是你用于Heroku的那个),我有一个叫做 Procfile.dev

  web:PORT = 3000 bundle exec puma -C config / puma.rb 

我用这个命令运行它:

  foreman start -f Procfile.dev 


I set the port as 3000 in my application.yml (figaro managing env variables) rails s uses port 3000 but when I run foreman start (as recommended by Heroku) I get the following output

14:53:23 web.1  | started with pid 24425
14:53:23 web.1  | [24425] Puma starting in cluster mode...
14:53:23 web.1  | [24425] * Version 2.11.1 (ruby 2.2.0-p0), codename: Intrepid Squirrel
14:53:23 web.1  | [24425] * Min threads: 5, max threads: 5
14:53:23 web.1  | [24425] * Environment: development
14:53:23 web.1  | [24425] * Process workers: 2
14:53:23 web.1  | [24425] * Preloading application
14:53:24 web.1  | WARNING: Skipping key "PORT". Already set in ENV.
14:53:25 web.1  | [24425] * Listening on tcp://0.0.0.0:5000
14:53:25 web.1  | [24425] Use Ctrl-C to stop
14:53:25 web.1  | [24425] - Worker 0 (pid: 24426) booted, phase: 0
14:53:25 web.1  | [24425] - Worker 1 (pid: 24427) booted, phase: 0

Procfile

web: bundle exec puma -C config/puma.rb

config/puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  ActiveRecord::Base.establish_connection
end

config/application.yml

PORT: "3000"

  • Rails 4.2.0
  • Foreman 0.78.0
  • Ruby 2.2.0p0
  • Puma 2.11.1

解决方案

Mystery on the puma port solved.

Put this print in your config/puma.rb

Then you'll see that somehow the port is mysteriously set to 5000 even though it is not in your ENV.

Fix at bottom.

puma_port = ENV['PORT'] || 3000
puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
puts "puma_port is #{puma_port}"
puts "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"

That prints out

16:49:28 web.1  | ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
16:49:28 web.1  | puma_port is 5000
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

Then place this line in your Procfile (not the one you use for Heroku). I've got one called Procfile.dev

web: PORT=3000 bundle exec puma -C config/puma.rb

And I run it with this command:

foreman start -f Procfile.dev

这篇关于Foreman / Puma没有在开发环境中使用指定的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆