我目前在Capistrano部署后遇到数据库连接问题。在数据库服务器上,似乎独角兽不会切断以前的连接,它只是不断添加旧的连接。我正在做一个preload true,如果重要的话,我也安装了章鱼宝石。我不太确定应该为此负责。我已经粘贴了我的独角兽配置来重要的部分。任何帮助表示赞赏!
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 aux”