Updated unicorn and capistrano configs

This commit is contained in:
Luke Barratt 2014-03-25 14:44:42 +00:00
parent 7a6cfb2df1
commit 74bb409a71
5 changed files with 21 additions and 11 deletions

View file

@ -12,9 +12,9 @@ set :keep_releases, 10
set :rbenv_type, :user set :rbenv_type, :user
set :rbenv_ruby, '2.1.1' set :rbenv_ruby, '2.1.1'
set :dotenv_role, [:app, :web]
set :unicorn_config_path, "config/unicorn.rb" set :unicorn_config_path, "config/unicorn.rb"
set :unicorn_rack_env, fetch(:rails_env)
set :writable_dirs, %w{public tmp} set :writable_dirs, %w{public tmp}
set :linked_files, %w{.env} set :linked_files, %w{.env}

View file

@ -1,5 +1,6 @@
set :branch, 'master' set :branch, 'master'
set :rails_env, 'production' set :rails_env, 'production'
set :unicorn_rack_env, fetch(:rails_env)
role :app, %w{deploy@ensl.org} role :app, %w{deploy@ensl.org}
role :web, %w{deploy@ensl.org} role :web, %w{deploy@ensl.org}

View file

@ -1,5 +1,6 @@
set :branch, 'develop' set :branch, 'develop'
set :rails_env, 'staging' set :rails_env, 'staging'
set :unicorn_rack_env, fetch(:rails_env)
role :app, %w{deploy@staging.ensl.org} role :app, %w{deploy@staging.ensl.org}
role :web, %w{deploy@staging.ensl.org} role :web, %w{deploy@staging.ensl.org}

View file

@ -1,10 +1,8 @@
require File.expand_path('../application', __FILE__) require File.expand_path('../application', __FILE__)
require 'dotenv'
require 'verification' require 'verification'
require 'exceptions' require 'exceptions'
require 'extra' require 'extra'
Dotenv.load
ActiveSupport::Deprecation.silenced = true if ['staging', 'production'].include?(ENV['RAILS_ENV']) ActiveSupport::Deprecation.silenced = true if ['staging', 'production'].include?(ENV['RAILS_ENV'])
Ensl::Application.initialize! Ensl::Application.initialize!

View file

@ -1,3 +1,6 @@
require "dotenv"
Dotenv.load
base_path = "/var/www/virtual/ensl.org/deploy" base_path = "/var/www/virtual/ensl.org/deploy"
current_path = "#{base_path}/current" current_path = "#{base_path}/current"
shared_path = "#{base_path}/shared" shared_path = "#{base_path}/shared"
@ -14,17 +17,24 @@ listen ENV['UNICORN_SOCKET'], :backlog => 64
stderr_path "#{shared_path}/log/unicorn.stderr.log" stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log" stdout_path "#{shared_path}/log/unicorn.stdout.log"
pid "#{shared_path}/tmp/pids/unicorn.pid" 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| before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect! ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid old_pid = "#{server.config[:pid]}.oldbin"
begin if old_pid != server.pid
Process.kill('QUIT', File.read(old_pid).to_i) begin
rescue Errno::ENOENT, Errno::ESRCH sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
end Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end end
end end