Remove code duplication for server startup/cleanup.