From 4ded88f04f499b6020d0148034e52178f28aec68 Mon Sep 17 00:00:00 2001 From: Mark Pundsack Date: Fri, 7 Feb 2014 17:00:31 -0800 Subject: [PATCH] Use Unicorn --- Gemfile | 1 + Gemfile.lock | 7 +++++++ Procfile | 1 + config/unicorn.rb | 25 +++++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 Procfile create mode 100644 config/unicorn.rb diff --git a/Gemfile b/Gemfile index 01e76c2..a22221b 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ ruby '2.1.0' gem 'rails', '4.0.2' gem 'rails_12factor', group: :production +gem 'unicorn' # Use postgresql as the database for Active Record gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 94775a8..3983639 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,7 @@ GEM railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) + kgio (2.9.1) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -75,6 +76,7 @@ GEM activesupport (= 4.0.2) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.12.0) rake (10.1.1) rdoc (4.1.1) json (~> 1.4) @@ -108,6 +110,10 @@ GEM uglifier (2.4.0) execjs (>= 0.3.0) json (>= 1.8.0) + unicorn (4.8.2) + kgio (~> 2.6) + rack + raindrops (~> 0.7) PLATFORMS ruby @@ -123,3 +129,4 @@ DEPENDENCIES sdoc turbolinks uglifier (>= 1.3.0) + unicorn diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9249f1e --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb \ No newline at end of file diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..67e638c --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,25 @@ +# config/unicorn.rb +worker_processes 3 +timeout 30 +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 sent QUIT' + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection +end \ No newline at end of file