diff --git a/config/unicorn/production.rb b/config/unicorn/production.rb index 757f4bf5d..bd23ffbeb 100644 --- a/config/unicorn/production.rb +++ b/config/unicorn/production.rb @@ -4,7 +4,7 @@ app_path = "/var/www/danbooru2/current" # Set unicorn options worker_processes 22 -preload_app false +preload_app true timeout 180 listen "127.0.0.1:9000" @@ -18,7 +18,7 @@ working_directory app_path rails_env = ENV['RAILS_ENV'] || 'production' # Log everything to one file -stderr_path "/dev/null" +stderr_path "#{app_path}/log/unicorn.log" stdout_path "/dev/null" # Set master PID location @@ -26,6 +26,7 @@ pid "#{app_path}/tmp/pids/unicorn.pid" before_fork do |server, worker| 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) @@ -33,8 +34,14 @@ before_fork do |server, worker| # someone else did our job for us end end + + if defined?(ActiveRecord::Base) + ActiveRecord::Base.connection.disconnect! + end end -# after_fork do |server, worker| -# ActiveRecord::Base.establish_connection -# end +after_fork do |server, worker| + if defined?(ActiveRecord::Base) + ActiveRecord::Base.establish_connection + end +end