From a977bb8cfa2b043e23ce03e53ea1c962855cb6ae Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Tue, 25 Mar 2014 14:44:42 +0000 Subject: [PATCH] Updated unicorn and capistrano configs --- config/deploy.rb | 2 +- config/deploy/production.rb | 1 + config/deploy/staging.rb | 1 + config/environment.rb | 2 -- config/unicorn.rb | 26 ++++++++++++++++++-------- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 898dc3d..409b370 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -12,9 +12,9 @@ set :keep_releases, 10 set :rbenv_type, :user set :rbenv_ruby, '2.1.1' +set :dotenv_role, [:app, :web] set :unicorn_config_path, "config/unicorn.rb" -set :unicorn_rack_env, fetch(:rails_env) set :writable_dirs, %w{public tmp} set :linked_files, %w{.env} diff --git a/config/deploy/production.rb b/config/deploy/production.rb index d643c97..88dfd67 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,5 +1,6 @@ set :branch, 'master' set :rails_env, 'production' +set :unicorn_rack_env, fetch(:rails_env) role :app, %w{deploy@ensl.org} role :web, %w{deploy@ensl.org} diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index a8f454d..80edfcd 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,5 +1,6 @@ set :branch, 'develop' set :rails_env, 'staging' +set :unicorn_rack_env, fetch(:rails_env) role :app, %w{deploy@staging.ensl.org} role :web, %w{deploy@staging.ensl.org} diff --git a/config/environment.rb b/config/environment.rb index 49305a8..5638ecb 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,10 +1,8 @@ require File.expand_path('../application', __FILE__) -require 'dotenv' require 'verification' require 'exceptions' require 'extra' -Dotenv.load ActiveSupport::Deprecation.silenced = true if ['staging', 'production'].include?(ENV['RAILS_ENV']) Ensl::Application.initialize! diff --git a/config/unicorn.rb b/config/unicorn.rb index 75b6eea..75ccd3f 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -1,3 +1,6 @@ +require "dotenv" +Dotenv.load + base_path = "/var/www/virtual/ensl.org/deploy" current_path = "#{base_path}/current" shared_path = "#{base_path}/shared" @@ -14,17 +17,24 @@ listen ENV['UNICORN_SOCKET'], :backlog => 64 stderr_path "#{shared_path}/log/unicorn.stderr.log" stdout_path "#{shared_path}/log/unicorn.stdout.log" pid "#{shared_path}/tmp/pids/unicorn.pid" - + +GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true + +before_exec do |server| + ENV["BUNDLE_GEMFILE"] = "#{current_path}/Gemfile" + Dotenv.overload +end + before_fork do |server, worker| ActiveRecord::Base.connection.disconnect! - - old_pid = "#{server.config[:pid]}.oldbin" - if File.exists?(old_pid) && server.pid != old_pid - begin - Process.kill('QUIT', File.read(old_pid).to_i) - rescue Errno::ENOENT, Errno::ESRCH - end + old_pid = "#{server.config[:pid]}.oldbin" + if old_pid != server.pid + begin + sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU + Process.kill(sig, File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + end end end