Start Discourse in an initializer (PR #9930)

Previously it was started using global variables in a script called preload-application-data.

This PR also includes some helpers for detecting the test environment which tidies things up.

GitHub