【问题标题】:Rails 4: Specified Unicorn in Procfile, but Webrick is executedRails 4:在 Procfile 中指定了 Unicorn,但执行了 Webrick
【发布时间】:2013-12-17 19:19:56
【问题描述】:

我使用的是 Rails 4.0.1,我想运行 unicorn 作为我的 web 服务器,但是当我执行 rails s 时,使用了 Webrick(unicorn gem 在我的 Gemfile 中,所以不能这样)。

这是我的 Procfile:

worker:  bundle exec rake jobs:work
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

这是 unicorn.rb 文件:

worker_processes 2
timeout 30
preload_app true

before_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

发生了什么事?谢谢!

【问题讨论】:

    标签: ruby-on-rails unicorn


    【解决方案1】:

    rails server 不使用您的Procfile;那是给foreman的。改为使用foreman 启动您的应用程序:

    bundle exec foreman start
    

    如果您希望 rails server 也使用 Unicorn,您可以包含 unicorn-rails gem。

    【讨论】:

      【解决方案2】:

      我将此作为一般帮助文章添加到那些因为在 Google 上进行相关搜索而登陆这里的人。

      如果您想运行 Unicorn,请将其添加到您的项目中

      宝石文件

      # Use unicorn as the app server
      gem 'unicorn'
      gem 'unicorn-rails'
      

      然后在你的终端运行bundle install

      然后你会在你的终端中得到这样的东西,表明你现在正在使用 Unicorn。

      => Booting Unicorn
      => Rails 4.0.0 application starting in development on http://0.0.0.0:3000
      => Run `rails server -h` for more startup options
      => Ctrl-C to shutdown server
      I, [2014-10-24T18:39:41.074259 #32835]  INFO -- : listening on addr=0.0.0.0:3000 fd=8
      I, [2014-10-24T18:39:41.074399 #32835]  INFO -- : worker=0 spawning...
      I, [2014-10-24T18:39:41.075407 #32835]  INFO -- : master process ready
      I, [2014-10-24T18:39:41.076712 #32836]  INFO -- : worker=0 spawned pid=32836
      I, [2014-10-24T18:39:41.237335 #32836]  INFO -- : worker=0 ready
      

      补充阅读
      Unicorn Rails
      Deploying to Heroku with Unicorn

      【讨论】:

        【解决方案3】:

        你需要通过运行foreman来启动一切,例如,

        $ foreman start
        

        否则你只是在启动 Rails 的默认服务器。

        有关更多背景信息,请参阅此Getting Started 指南。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-18
          • 1970-01-01
          • 1970-01-01
          • 2017-08-29
          • 2014-02-07
          • 1970-01-01
          相关资源
          最近更新 更多