我目前在部署 Capistrano 后遇到数据库连接问题。在数据库服务器上,似乎独角兽并没有切断以前的连接,它只是不断地在旧连接之上添加。我正在做一个预加载,如果这很重要,我也安装了章鱼 gem。我不太确定这应该归咎于谁。我已经为重要的部分粘贴了我的独角兽配置。任何帮助表示赞赏!
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
old_pid = "/tmp/unicorn.my_app_name.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
end
end
after_fork do |server, worker|
ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each {|k,v| v.clear_reloadable_connections! }
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
if Process.ppid > 1 # Not the daemon
child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid")
File.open(child_pid, "wb") {|f| f << Process.pid }
end
end
“ps辅助”