diff options
| -rw-r--r-- | Gemfile | 4 | ||||
| -rw-r--r-- | Gemfile.lock | 7 | ||||
| -rw-r--r-- | Procfile | 1 | ||||
| -rw-r--r-- | config/unicorn.rb | 20 |
4 files changed, 32 insertions, 0 deletions
@@ -13,3 +13,7 @@ end group :development, :test do gem 'rspec-rails' end + +group :production do + gem 'unicorn' +end diff --git a/Gemfile.lock b/Gemfile.lock index 3f653bd..860c002 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM activesupport (>= 3.0.0) multi_json (>= 1.2.0) json (1.8.1) + kgio (2.9.2) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -60,6 +61,7 @@ GEM activesupport (= 4.0.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.13.0) rake (10.1.1) rdoc (4.1.1) json (~> 1.4) @@ -95,6 +97,10 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.38) + unicorn (4.8.2) + kgio (~> 2.6) + rack + raindrops (~> 0.7) PLATFORMS ruby @@ -105,3 +111,4 @@ DEPENDENCIES rails (= 4.0.3) rspec-rails sdoc + unicorn diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9c82374 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +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..729ff4d --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,20 @@ +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 |
