WIP: trying to get database engine startup/shutdown to work. Fixed some other issues with logging hanging and blocking the system.