我想部署在Puma和jruby上运行的Rails应用程序。该Procfile是如下的彪马在Heroku中部署Rama应用程序时发生错误
web: bundle exec puma -C config/puma.rb -p $PORT -e $RACK_ENV
配置放在
配置/ puma.rb
if ENV['RACK_ENV'] != 'production' || ENV['RAILS_ENV'] != 'production'
workers Integer(ENV['PUMA_WORKERS'] || 4)
end
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 4)
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
preload_app!
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 16
ActiveRecord::Base.establish_connection(config)
end
end
我有工人有条件初始化的原因是因为Heroku的抱怨(或可能是Puma)工作模式不适用于JRuby和Windows;反正,
奇怪的行为我在Heroku注意的是,(不像)我的本地环境中的群集彪马实例启动时没有任何问题,并拿起两个不同的端口绑定,即3000和5000
然而,生产即Heroku这导致崩溃
2014-06-23T08:50:54.545724+00:00 heroku[web.1]: State changed from crashed to starting
2014-06-23T08:51:02.510184+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCodebaseOnly=true
2014-06-23T08:51:01.333763+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb -p 49576 -e production`
2014-06-23T08:51:21.658663+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Djava.rmi.server.useCodebaseOnly=true
2014-06-23T08:51:44.964380+00:00 app[web.1]: * Version 2.8.2 (jruby 1.9.3), codename: Sir Edmund Percival Hillary
2014-06-23T08:51:44.962724+00:00 app[web.1]: The signal USR1 is in use by the JVM and will not work correctly on this platform
2014-06-23T08:51:44.964563+00:00 app[web.1]: * Min threads: 1, max threads: 4
2014-06-23T08:51:44.964738+00:00 app[web.1]: * Environment: production
2014-06-23T08:51:44.963925+00:00 app[web.1]: Puma starting in single mode...
2014-06-23T08:51:57.852471+00:00 app[web.1]: Errno::EADDRINUSE: Address already in use - bind - Address already in use
2014-06-23T08:51:57.830580+00:00 app[web.1]: * Listening on tcp://0.0.0.0:49576
2014-06-23T08:51:57.852474+00:00 app[web.1]: initialize at org/jruby/ext/socket/RubyTCPServer.java:118
2014-06-23T08:51:57.852478+00:00 app[web.1]: add_tcp_listener at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/binder.rb:195
2014-06-23T08:51:57.852476+00:00 app[web.1]: new at org/jruby/RubyIO.java:852
2014-06-23T08:51:57.850256+00:00 app[web.1]: * Listening on tcp://0.0.0.0:49576
2014-06-23T08:51:57.852479+00:00 app[web.1]: parse at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/binder.rb:96
2014-06-23T08:51:57.852481+00:00 app[web.1]: each at org/jruby/RubyArray.java:1613
2014-06-23T08:51:57.852482+00:00 app[web.1]: parse at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/binder.rb:82
2014-06-23T08:51:57.852484+00:00 app[web.1]: load_and_bind at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/runner.rb:119
2014-06-23T08:51:57.852486+00:00 app[web.1]: run at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/single.rb:73
2014-06-23T08:51:57.852487+00:00 app[web.1]: run at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/lib/puma/cli.rb:499
2014-06-23T08:51:57.852489+00:00 app[web.1]: (root) at /app/vendor/bundle/jruby/1.9/gems/puma-2.8.2-java/bin/puma:10
2014-06-23T08:51:57.852491+00:00 app[web.1]: load at org/jruby/RubyKernel.java:1099
2014-06-23T08:51:57.852492+00:00 app[web.1]: (root) at /app/vendor/bundle/jruby/1.9/bin/puma:23
2014-06-23T08:51:59.347012+00:00 heroku[web.1]: State changed from starting to crashed
2014-06-23T08:51:59.333790+00:00 heroku[web.1]: Process exited with status 1
当我在我的笔记本电脑上运行它时看不到这种奇怪的启动行为。
我有美洲狮在Heroku的JRuby的工作的唯一方法是通过这个设置
if ENV['RACK_ENV'] != 'production' || ENV['RAILS_ENV'] != 'production'
workers Integer(ENV['PUMA_WORKERS'] || 4)
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
end
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 4)
rackup DefaultRackup
preload_app!
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 16
ActiveRecord::Base.establish_connection(config)
end
end
即如果端口和环境指令是从侧if块的Heroku莫名其妙试图运行在相同的两个实例端口,这显然会导致崩溃。
我错过任何配置在这里或在集群模式下运行的基本(我甚至尝试了,而不是JRuby的红宝石2.0.0运行)只是在Heroku的
不可能*更新*
Procfile
web: bundle exec puma -C config/puma.rb
配置/ puma.rb
if ENV['RACK_ENV'] != 'production' || ENV['RAILS_ENV'] != 'production'
workers Integer(ENV['PUMA_WORKERS'] || 4)
end
threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 16)
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
preload_app!
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
config = ActiveRecord::Base.configurations[Rails.env] ||
Rails.application.config.database_configuration[Rails.env]
config['pool'] = ENV['MAX_THREADS'] || 16
ActiveRecord::Base.establish_connection(config)
end
end
原因条件块(从最初的问题说明引述
我有工人有条件的初始化是因为 Heroku的抱怨(或可能是彪马)工人模式的原因不适用于 JRuby和Windows;
和错误日志(即使我删除JRUBY,有条件的工人块),并尝试在集群模式下
606 2014-06-23T07:13:42.058507+00:00 heroku[api]: Release v35 created by [email protected]
607 2014-06-23T07:13:47.674708+00:00 app[web.1]: [2] Puma starting in cluster mode...
608 2014-06-23T07:13:47.674777+00:00 app[web.1]: [2] * Version 2.8.2 (ruby 2.1.1-p76), codename: Sir Edmund Percival Hillary
609 2014-06-23T07:13:47.674816+00:00 app[web.1]: [2] * Min threads: 1, max threads: 16
610 2014-06-23T07:13:47.674939+00:00 app[web.1]: [2] * Preloading application
611 2014-06-23T07:13:47.674858+00:00 app[web.1]: [2] * Environment: production
612 2014-06-23T07:13:47.674900+00:00 app[web.1]: [2] * Process workers: 4
613 2014-06-23T07:13:49.078330+00:00 app[web.1]: [2] * Listening on tcp://0.0.0.0:45245
614 2014-06-23T07:13:49.078766+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `initialize': Address already in use - bind(2) for "0.0.0.0 " port 45245 (Errno::EADDRINUSE)
615 2014-06-23T07:13:49.078775+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `add_tcp_listener'
616 2014-06-23T07:13:49.078771+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `new'
617 2014-06-23T07:13:49.078780+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:82:in `each'
618 2014-06-23T07:13:49.078785+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/runner.rb:119:in `load_and_bind'
619 2014-06-23T07:13:49.078778+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:96:in `block in parse'
620 2014-06-23T07:13:49.078784+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:82:in `parse'
621 2014-06-23T07:13:49.078793+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/cli.rb:499:in `run'
622 2014-06-23T07:13:49.078789+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/cluster.rb:271:in `run'
623 2014-06-23T07:13:49.078794+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/bin/puma:10:in `<top (required)>'
624 2014-06-23T07:13:49.078798+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bin/puma:23:in `load'
625 2014-06-23T07:13:49.078801+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bin/puma:23:in `<main>'
626 2014-06-23T07:13:49.078565+00:00 app[web.1]: [2] * Listening on tcp://0.0.0.0:45245
627 2014-06-23T07:13:50.359244+00:00 heroku[web.1]: Process exited with status 1
628 2014-06-23T07:13:45.838792+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb -p 45245 -e production`
629 2014-06-23T07:13:50.385427+00:00 heroku[web.1]: State changed from starting to crashed
630 2014-06-23T07:13:50.385913+00:00 heroku[web.1]: State changed from crashed to starting
631 2014-06-23T07:13:57.445391+00:00 app[web.1]: [2] Puma starting in cluster mode...
632 2014-06-23T07:13:57.445417+00:00 app[web.1]: [2] * Environment: production
633 2014-06-23T07:13:57.445413+00:00 app[web.1]: [2] * Version 2.8.2 (ruby 2.1.1-p76), codename: Sir Edmund Percival Hillary
634 2014-06-23T07:13:57.445415+00:00 app[web.1]: [2] * Min threads: 1, max threads: 16
635 2014-06-23T07:13:57.445419+00:00 app[web.1]: [2] * Process workers: 4
636 2014-06-23T07:13:57.445423+00:00 app[web.1]: [2] * Preloading application
637 2014-06-23T07:13:54.371058+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb -p 33243 -e production`
638 2014-06-23T07:13:59.883490+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `initialize': Address already in use - bind(2) for "0.0.0.0 " port 33243 (Errno::EADDRINUSE)
639 2014-06-23T07:13:59.882892+00:00 app[web.1]: [2] * Listening on tcp://0.0.0.0:33243
640 2014-06-23T07:13:59.883501+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:96:in `block in parse'
641 2014-06-23T07:13:59.883494+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `new'
642 2014-06-23T07:13:59.883499+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:195:in `add_tcp_listener'
643 2014-06-23T07:13:59.883506+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:82:in `parse'
644 2014-06-23T07:13:59.883510+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/runner.rb:119:in `load_and_bind'
645 2014-06-23T07:13:59.883503+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/binder.rb:82:in `each'
646 2014-06-23T07:13:59.883512+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/cluster.rb:271:in `run'
647 2014-06-23T07:13:59.883519+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bin/puma:23:in `load'
648 2014-06-23T07:13:59.883517+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/bin/puma:10:in `<top (required)>'
649 2014-06-23T07:13:59.883514+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/gems/puma-2.8.2/lib/puma/cli.rb:499:in `run'
650 2014-06-23T07:13:59.883525+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.1.0/bin/puma:23:in `<main>'
651 2014-06-23T07:13:59.883273+00:00 app[web.1]: [2] * Listening on tcp://0.0.0.0:33243
652 2014-06-23T07:14:01.451472+00:00 heroku[api]: Set DEV-2-PASS config vars by [email protected]
653 2014-06-23T07:14:01.451540+00:00 heroku[api]: Release v36 created by [email protected]
654 2014-06-23T07:14:01.624035+00:00 heroku[web.1]: State changed from starting to crashed
655 2014-06-23T07:14:01.963688+00:00 heroku[web.1]: State changed from crashed to starting
656 2014-06-23T07:14:01.615855+00:00 heroku[web.1]: Process exited with status 1
谢谢!我没有注意到冗余,但仍然不能解决它在Heroku上,即使保留端口和环境只在prima.rb –
您是使用旧的puma.rb还是新的? 所有这些'如果ENV ['RACK_ENV']!='生产'|| ENV ['RAILS_ENV']!='production''不应该是必需的。 如果您希望工人的数量默认为一个更改'ENV ['PUMA_WORKERS'] || 4'到'ENV ['PUMA_WORKERS'] || 1' – tmaier
请查看关于问题的更新,我已经解释了更新配置后条件块的原因和状态。 –