Search code examples
ruby-on-railsunicorn

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


I am using Rails 4.0.1 and I want to run unicorn as my web server, but when I execute rails s, Webrick is used instead (the unicorn gem is in my Gemfile, so it can't be that).

This is my Procfile:

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

And this is the unicorn.rb file:

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

What is going on? Thanks!


Solution

  • rails server doesn't use your Procfile; that's for foreman. Start your application with foreman instead:

    bundle exec foreman start
    

    If you want rails server to use Unicorn as well, you can include the unicorn-rails gem.