簡體   English   中英

Rails 4:Procfile中指定的Unicorn,但Webrick被執行

[英]Rails 4: Specified Unicorn in Procfile, but Webrick is executed

我正在使用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

到底是怎么回事? 謝謝!

rails server不使用您的Procfile ; 那是工頭 改為與foreman開始申請:

bundle exec foreman start

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

我將此作為一般幫助文章添加到那些因為在Google上進行相關搜索而在此處登陸的文章。

如果要運行Unicorn,請在項目中添加

的Gemfile

# 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部署到Heroku

你需要通過運行工頭開始一切,例如,

$ foreman start

否則你只是啟動Rails的默認服務器。

有關更多背景信息,請參閱此入門指南

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM