How can I use unicorn as “rails s”?

房东的猫 提交于 2019-11-28 18:32:33
Stuart M

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).

A better option might just be to run the unicorn server directly.

bundle exec unicorn -p 3000 # default port is 8080
gem 'rack-handlers'

rails server unicorn

However the answer by Steven is the simplest way to do.

I run unicorn on development environment via a 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

run:

rake s

Reference http://jing.io

I don't think it is possible to use unicorn as 'rails s'. Use this -

Add gem 'unicorn' to gem file and run bundle install.

and then run any of the following commands -

$ unicorn -p 3000

or

$ unicorn_rails -p 3000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!