Move server startup code into function.