Browse Source

Bundle unicorn for production deployments.

master
Georg Hopp 10 years ago
parent
commit
71dfbd93f4
  1. 2
      Gemfile
  2. 7
      Gemfile.lock
  3. 24
      config/unicorn.rb
  4. 23
      run_unicorn.md

2
Gemfile

@ -30,7 +30,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server # Use Unicorn as the app server
# gem 'unicorn'
gem 'unicorn'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development

7
Gemfile.lock

@ -60,6 +60,7 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3) json (1.8.3)
kgio (2.10.0)
loofah (2.0.3) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.4) mail (2.6.4)
@ -97,6 +98,7 @@ GEM
activesupport (= 4.2.6) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.16.0)
rake (11.1.2) rake (11.1.2)
rdoc (4.2.2) rdoc (4.2.2)
json (~> 1.4) json (~> 1.4)
@ -123,6 +125,10 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (3.0.0) uglifier (3.0.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unicorn (5.0.1)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
web-console (2.3.0) web-console (2.3.0)
activemodel (>= 4.0) activemodel (>= 4.0)
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
@ -147,6 +153,7 @@ DEPENDENCIES
tilt (~> 2.0) tilt (~> 2.0)
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
unicorn
web-console (~> 2.0) web-console (~> 2.0)
BUNDLED WITH BUNDLED WITH

24
config/unicorn.rb

@ -0,0 +1,24 @@
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
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 send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
# vim: set ts=2 sw=2:

23
run_unicorn.md

@ -0,0 +1,23 @@
# Some notes about unicorn
First off, it only servers the rails application, not the static assets.
You need to have another webserver for this.
## SECRET_KEY
By default rails reads the secret key from the environment variable
`SECRET_KEY_BASE`. It is possible to create a key with `rake secret`
## Start unicorn
SECRET_KEY_BASE="fa27f9d1cdfeb8590377366cb89c973b6084a20b60a4e60b551563cb1119156a0f172212f54fc096e182bf5310b6ca8cb050814c5908c8523cb191d1a054ca29" bundle exec unicorn -c config/unicorn.rb -E production
## Precompile assets
RAILS_ENV=production bundle exec rake assets:precompile
## Urls
* [heroku:Deploying Rails Applications with Unicorn](https://devcenter.heroku.com/articles/rails-unicorn)
* [DigitalOcean:How To Deploy a Rails App with Unicorn and Nginx on Ubuntu 14.04](https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04)
Loading…
Cancel
Save