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.

Hopefully fixes https://bugs.launchpad.net/juju-core/+bug/1348477
can we move this closer to where it's used