How can I use unicorn as "rails s"?
Solution 1
It looks like the unicorn-rails
gem that @Dogbert mentioned can actually be used to make Unicorn the rails server
handler.
Simply include gem "unicorn-rails"
(and for Rails 4.2.4, gem "rack-handlers"
) in your Gemfile
, run bundle install
to install the gem, then you can run:
$ rails server unicorn
Although once unicorn-rails
is installed, Unicorn should be the default app server so you could also just run rails server
and it should use Unicorn (assuming you don't also have Thin or Mongrel in your Gemfile
, in which case they may conflict and you might want to remove the ones you're not using).
Solution 2
A better option might just be to run the unicorn server directly.
bundle exec unicorn -p 3000 # default port is 8080
Solution 3
gem 'rack-handlers'
rails server unicorn
patrick
Updated on July 09, 2022Comments
-
patrick almost 2 years
A new Rails project's
Gemfile
shows:# Use unicorn as the app server gem 'unicorn'
rails s --help
shows:Usage: rails server [mongrel, thin, etc] [options]
Yet, doing:
rails s unicorn
I get:
/Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:in `require': cannot load such file -- rack/handler/unicorn (LoadError) from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:63:in `try_require' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/handler.rb:16:in `get' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/rack-1.4.5/lib/rack/server.rb:272:in `server' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands/server.rb:59:in `start' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:55:in `block in <top (required)>' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap' from /Users/patrick/.rvm/gems/ruby-1.9.3-head@keynote/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
I've used unicorn in the past on other projects, but always had to run the
unicorn
command and specify a config file which is a bit of a pain. I am wondering how I can just simply make it work by usingrails s...
Is this possible?
-
patrick about 11 yearsI find it very interesting that the gemfile has 'unicorn' rather than 'unicorn_rails' as a suggestion. I also find it interesting that this webpage says: "unicorn_rails was made to be an easier transition for users of pre-Rack versions of Rails. The manpage encourages Rails 3 users to use plain unicorn instead." blog.engineyard.com/2010/…
-
Stuart M about 11 yearsWhich Gemfile are you seeing
unicorn
in? I suggested adding theunicorn-rails
gem to your Gemfile. -
Eric Caron over 10 yearsThe other beauty of using rack-handlers is that it autoloads the config/unicorn.rb file.
-
Evan over 8 yearsFor Rails 4.2.4, this first requires adding
gem 'rack-handlers'
to your Gemfile along withgem 'unicorn'
-
Huzaifa Saifuddin over 6 yearsHow can i increase Workers?