Fix crash on SIGTERM
Discovery db fixup (preliminary)