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.
Question
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.
OTHER TIPS
I am adding this as a general help article to those that have landed here because of a related search on Google.
If you want to run Unicorn then add this in your project
# Use unicorn as the app server
gem 'unicorn'
gem 'unicorn-rails'
Then in your terminal run bundle install
You will then get something like this in your terminal that shows that you are now using 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
Additional Reading
Unicorn Rails
Deploying to Heroku with Unicorn
You need to start everything by running foreman, e.g.,
$ foreman start
Otherwise you're just starting up Rails' default server.
See this Getting Started guide for further background info.