Reorder the closing of resources.

There seemed to be some ordering issues with the tear down.

We should be closing any api connections first, as they depend on the state connection.
Then we should close the state connection.
Once all that is done, we should reset the mongo admin password.