Add a few improvements to stability

This improves on a few issues which are not frequent but do sometimes
come up:

1. Check that the daemon is up before attempting to do anything
   docker-ey in provisioning Ubuntu
2. Set a max retries for SSH so that if a request fails it attempts
   again before giving up

Also have annotated a few of the SSH options slightly better.

Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
This commit is contained in:
Nathan LeClaire
2015-04-06 12:58:19 -07:00
parent d0d9aa2d47
commit 29999e9b10
2 changed files with 24 additions and 2 deletions

View File

@@ -5,10 +5,12 @@ import (
"fmt"
"os/exec"
log "github.com/Sirupsen/logrus"
"github.com/docker/machine/drivers"
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/provision/pkgaction"
"github.com/docker/machine/libmachine/swarm"
"github.com/docker/machine/utils"
)
func init() {
@@ -80,6 +82,21 @@ func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.Pack
return nil
}
func (provisioner *UbuntuProvisioner) dockerDaemonResponding() bool {
cmd, err := provisioner.SSHCommand("sudo docker version")
if err != nil {
log.Warn("Error getting SSH command to check if the daemon is up: %s", err)
return false
}
if err := cmd.Run(); err != nil {
log.Debug("Error checking for daemon up: %s", err)
return false
}
// The daemon is up if the command worked. Carry on.
return true
}
func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions) error {
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
@@ -95,6 +112,10 @@ func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.SwarmOptions,
return err
}
if err := utils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
if err := ConfigureAuth(provisioner, authOptions); err != nil {
return err
}