replica: Proper shutdown of database and avoid database singleton

Target: trunk
Require-notes: yes
Require-book: no
Acked-by: Albert Rossir <arossi@fnal.gov>
Patch: https://rb.dcache.org/r/7379/