Revert "Now using Canarys's database API."

This reverts commit 237fc691c181aa4fb7626ff431a4ac6d92a16497.
Replaced the shutdown thread with a hook.