Updated unicorn and capistrano configs

This commit is contained in:
Luke Barratt 2014-03-25 14:44:42 +00:00
parent e337d0580a
commit a977bb8cfa
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_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}

View file

@ -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}

View file

@ -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}

View file

@ -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!

View file

@ -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