Allow restore to retry connecting to state server

The restore process recreates a state server but it may not have finished starting everything before attempting to reconnect. So a retry loop is added where needed. Tested live on EC2, first to reproduce the bug and then to verify the fix.

Fixes: https://bugs.launchpad.net/juju-core/+bug/1336104