diff --git a/Gemfile b/Gemfile index 9326822..83d4e4f 100644 --- a/Gemfile +++ b/Gemfile @@ -32,8 +32,8 @@ group :development, :test do end group :production do - gem 'puma' gem 'skylight' + gem 'unicorn' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 9c6dd52..f3ec233 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,6 +93,7 @@ GEM kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) + kgio (2.9.3) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.3) @@ -114,7 +115,6 @@ GEM coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - puma (2.13.4) rack (1.6.4) rack-pjax (0.8.0) nokogiri (~> 1.5) @@ -165,6 +165,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) + raindrops (0.15.0) rake (10.4.2) remotipart (1.2.1) responders (2.1.0) @@ -218,6 +219,10 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.1) + unicorn (4.9.0) + kgio (~> 2.6) + rack + raindrops (~> 0.7) validates_formatting_of (0.9.0) activemodel warden (1.2.3) @@ -240,7 +245,6 @@ DEPENDENCIES nokogiri pg pry - puma rails (~> 4.2.4) rails_12factor rails_admin @@ -251,6 +255,7 @@ DEPENDENCIES spring sqlite3 uglifier + unicorn validates_formatting_of webmock diff --git a/Procfile b/Procfile index 4fd3163..9c82374 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bundle exec puma -p $PORT +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..894ea79 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,18 @@ +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 + 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 + ActiveRecord::Base.establish_connection +end