我正在使用Rails 4.0.1并且我想运行独角兽作为我的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
发生了什么事?谢谢!
答案 0 :(得分:3)
rails server
不使用您的Procfile
;这是foreman的。请使用foreman
启动您的申请:
bundle exec foreman start
如果您希望rails server
也使用Unicorn,则可以添加unicorn-rails gem。
答案 1 :(得分:3)
我将此作为一般性帮助文章添加到那些因为在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
答案 2 :(得分:1)