Ruby-on-rails 如何将独角兽用作“rails”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15858887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use unicorn as "rails s"?
提问by patrick
A new Rails project's Gemfileshows:
一个新的 Rails 项目Gemfile显示:
# Use unicorn as the app server
gem 'unicorn'
rails s --helpshows:
rails s --help显示:
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 unicorncommand and specify a config file which is a bit of a pain. I am wondering how I can just simply make it work by using rails s...
我过去在其他项目中使用过 unicorn,但总是不得不运行unicorn命令并指定一个配置文件,这有点麻烦。我想知道如何通过使用简单地使其工作rails s...
Is this possible?
这可能吗?
回答by Stuart M
It looks like the unicorn-railsgem that @Dogbert mentioned can actually be used to make Unicorn the rails serverhandler.
看起来unicorn-rails@Dogbert 提到的gem 实际上可以用来使 Unicorn 成为rails server处理程序。
Simply include gem "unicorn-rails"(and for Rails 4.2.4, gem "rack-handlers") in your Gemfile, run bundle installto install the gem, then you can run:
只需在您的, 运行中包含gem "unicorn-rails"(对于 Rails 4.2.4,gem "rack-handlers")以安装 gem,然后您可以运行:Gemfilebundle install
$ rails server unicorn
Although once unicorn-railsis installed, Unicorn should be the default app server so you could also just run rails serverand 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).
虽然一旦unicorn-rails安装,Unicorn 应该是默认的应用程序服务器,所以你也可以直接运行rails server,它应该使用 Unicorn(假设你Gemfile的 .那些你没有使用的)。
回答by Steven Soroka
A better option might just be to run the unicorn server directly.
更好的选择可能只是直接运行 unicorn 服务器。
bundle exec unicorn -p 3000 # default port is 8080
回答by Tom Maeckelberghe
gem 'rack-handlers'
rails server unicorn
回答by tokhi
However the answer by Stevenis the simplest way to do.
然而,答案Steven是最简单的方法。
I run unicornon development environment via a rake task:
我unicorn通过 rake 任务在开发环境中运行:
lib/tasks/dev_unicorn.rake:
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
run:
跑:
rake s
rake s
Reference http://jing.io
回答by prashant
I don't think it is possible to use unicorn as 'rails s'. Use this -
我认为不可能将独角兽用作“rails”。用这个 -
Add gem 'unicorn' to gem file and run bundle install.
将 gem 'unicorn' 添加到 gem 文件并运行 bundle install。
and then run any of the following commands -
然后运行以下任何命令 -
$ unicorn -p 3000
$ 独角兽 -p 3000
or
或者
$ unicorn_rails -p 3000
$ unicorn_rails -p 3000

