secret
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
rails_env = ENV['RAILS_ENV'] || 'development'
 
# thorn is having some swap problems, lowinger # servers to 4 since it's running two sites now
num_workers = 6
worker_processes num_workers
 
preload_app true
timeout 20
 
if `hostname` =~ /rose|everybean/
listen '/tmp/pro.unicorn.sock', :backlog => 128
else
listen 3001, :backlog => 128
end
 
app_base = "/u/apps/ap.pro"
 
stderr_path "/tmp/pro.err.unicorn"
stdout_path "/tmp/pro.out.unicorn"
pid "#{app_base}/shared/pids/pro.unicorn.pid"
working_directory "#{app_base}/current"
user 'kevin', 'kevin' if `hostname` !~ /everybean|duke/
 
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "#{app_base}/current/Gemfile"
end
 
before_fork do |server, worker|
# USR2 = restart gracefully
# old_pid = '/tmp/pro.unicorn.pid.oldbin'
old_pid = "#{app_base}/shared/pids/pro.unicorn.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
# someone else did our job for us
end
end
 
ActiveRecord::Base.connection.disconnect!
end
 
# runs in the 'ruby' environment/etc
after_fork do |server, worker|
# reconnect db
db = $cache['db']
if Rails.env.production?
c = $cache.get('db') || 'memory'
# d "new unicorn connecting to #{c}"
ActiveRecord::Base.establish_connection c
$db_current = c
elsif Rails.env.development?
ActiveRecord::Base.establish_connection( 'development' )
end
begin
Rails.cache.reset
$cache.reset
rescue Exception => e
d "rescued unicorn exception #{e.class} #{e.message}"
end
end
 
# will just this be enough? Hmm, do some tests w/ adding + removing gems?
before_exec do |server|
ENV["BUNDLE_GEMFILE"] = "/u/apps/ap.pro/current/Gemfile"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.