Fix prefork mode

Connections to to DB and cache need to be closed at the end of the startup procedures, because those are not fork safe and cause problems when running Askbot in prefork mode