title: Unicorn does not sever database connections properly after new deploy
body: <p>I am currently having a problem with database connections after a Capistrano deploy. On the database server it seems like unicorn does not sever the previous connections and it just keeps adding on top of the old ones. I am doing a preload true, and I also have octopus gem installed as well if that matters. I am not too sure who is to blame for this. I have pasted my unicorn config for the part that matters. Any help is appreciated! </p>
  
  <pre><code>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) &amp;&amp; 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 &gt; 1 # Not the daemon
    child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid")
    File.open(child_pid, "wb") {|f| f &lt;&lt; Process.pid }
    end
  end
  </code></pre>
  
  <p><img src="https://i.imgur.com/HVkkM.png" alt="1"> "ps aux"</p>