How can I use a unicorn as "rails"?

The new rails gimfile project displays:

# Use unicorn as the app server gem 'unicorn' 

rails s --help shows:

 Usage: rails server [mongrel, thin, etc] [options] 

However, by 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 used the unicorn in the past in other projects, but I always had to run the unicorn command and specify a configuration file that hurts a little. I am wondering how can I just make it work using "rails s" ... Is this possible?

+48
ruby ruby-on-rails unicorn
Apr 07 '13 at 4:33
source share
5 answers

It looks like the unicorn-rails gem that @Dogbert mentioned can really be used to make Unicorn the rails server handler.

Just add gem "unicorn-rails" (and for Rails 4.2.4, gem "rack-handlers" ) to the Gemfile , run bundle install to install the gem, then you can run:

 $ rails server unicorn 

Although unicorn-rails installed once, Unicorn must be the default application server so that you can just start the rails server , and it must use Unicorn (if you do not use Thin or Mongrel in your Gemfile , in this case they may conflict, and you can remove those that you don’t use).

+57
Apr 07 '13 at 7:28
source share

A better option would be to simply start the unicorn server.

 bundle exec unicorn -p 3000 # default port is 8080 
+24
01 Sep '13 at 2:31 on
source share
 gem 'rack-handlers' rails server unicorn 
+16
Dec 11 '13 at 14:36
source share

I do not think that you can use a unicorn as a "railing". Use it -

Add gem 'unicorn' to the gem file and run the package installation.

and then run any of the following commands -

$ unicorn -p 3000

or

$ unicorn_rails -p 3000

+1
Dec 28 '14 at 8:39
source share

However, Steven answer is the easiest way.

I run unicorn in a development environment using the rake task:

Lib / tasks / dev_unicorn.rake:

 task :server do # optional port parameter port = ENV['PORT'] ? ENV['PORT'] : '3000' puts 'start unicorn development' # execute unicorn command specifically in development # port at 3000 if unspecified sh "cd #{Rails.root} && RAILS_ENV=development unicorn -p #{port}" end # an alias task task :s => :server 

mileage:

rake s

Link http://jing.io

0
Nov 12 '14 at 15:30
source share



All Articles