From d6db67d0be272ae5981818696d215066c39752f9 Mon Sep 17 00:00:00 2001 From: Nathan LeClaire Date: Thu, 26 Mar 2015 16:35:27 -0700 Subject: [PATCH] Fix unix:// not working inside VM issue With the way that provisioning was implemented, there was an issue getting connection to the UNIX socket to work with the new boot2docker 1.6rc2 ISO. This issue is related to the fact that the docker service was not truly stopped during the provisioning. This PR fixes the issue and provides some tests to help ensure that it does not come up again. Signed-off-by: Nathan LeClaire --- libmachine/provision/boot2docker.go | 22 +++++++++++++++------- test/integration/driver-amazonec2.bats | 4 ++++ test/integration/driver-digitalocean.bats | 4 ++++ test/integration/driver-virtualbox.bats | 4 ++++ utils/utils.go | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/libmachine/provision/boot2docker.go b/libmachine/provision/boot2docker.go index 2935775976..5c9a3ef992 100644 --- a/libmachine/provision/boot2docker.go +++ b/libmachine/provision/boot2docker.go @@ -10,6 +10,7 @@ import ( "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() { @@ -35,13 +36,9 @@ func (provisioner *Boot2DockerProvisioner) Service(name string, action pkgaction cmd *exec.Cmd err error ) - if name == "docker" && action == pkgaction.Stop { - cmd, err = provisioner.SSHCommand("if [ -e /var/run/docker.pid ] && [ -d /proc/$(cat /var/run/docker.pid) ]; then sudo /etc/init.d/docker stop ; exit 0; fi") - } else { - cmd, err = provisioner.SSHCommand(fmt.Sprintf("sudo /etc/init.d/%s %s", name, action.String())) - if err != nil { - return err - } + cmd, err = provisioner.SSHCommand(fmt.Sprintf("sudo /etc/init.d/%s %s", name, action.String())) + if err != nil { + return err } if err := cmd.Run(); err != nil { return err @@ -119,6 +116,17 @@ func (provisioner *Boot2DockerProvisioner) Provision(swarmOptions swarm.SwarmOpt return err } + ip, err := provisioner.GetDriver().GetIP() + if err != nil { + return err + } + + // b2d hosts need to wait for the daemon to be up + // before continuing with provisioning + if err := utils.WaitForDocker(ip, 2376); err != nil { + return err + } + if err := ConfigureAuth(provisioner, authOptions); err != nil { return err } diff --git a/test/integration/driver-amazonec2.bats b/test/integration/driver-amazonec2.bats index 610f97c7ea..439ebd570f 100644 --- a/test/integration/driver-amazonec2.bats +++ b/test/integration/driver-amazonec2.bats @@ -48,6 +48,10 @@ export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER [[ ${lines[0]} =~ "total" ]] } +@test "$DRIVER: docker commands with the socket should work" { + run machine ssh $NAME -- docker version +} + @test "$DRIVER: stop" { run machine stop $NAME [ "$status" -eq 0 ] diff --git a/test/integration/driver-digitalocean.bats b/test/integration/driver-digitalocean.bats index 464d43b807..c363698d65 100644 --- a/test/integration/driver-digitalocean.bats +++ b/test/integration/driver-digitalocean.bats @@ -48,6 +48,10 @@ export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER [[ ${lines[0]} =~ "total" ]] } +@test "$DRIVER: docker commands with the socket should work" { + run machine ssh $NAME -- docker version +} + @test "$DRIVER: stop" { run machine stop $NAME [ "$status" -eq 0 ] diff --git a/test/integration/driver-virtualbox.bats b/test/integration/driver-virtualbox.bats index c138e20540..2222ba2cb5 100644 --- a/test/integration/driver-virtualbox.bats +++ b/test/integration/driver-virtualbox.bats @@ -63,6 +63,10 @@ function setup() { [[ ${lines[0]} =~ "total" ]] } +@test "$DRIVER: docker commands with the socket should work" { + run machine ssh $NAME -- docker version +} + @test "$DRIVER: stop" { run machine stop $NAME [ "$status" -eq 0 ] diff --git a/utils/utils.go b/utils/utils.go index be065951bd..a6c4e4fd01 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -100,7 +100,7 @@ func WaitForDocker(ip string, daemonPort int) error { return WaitFor(func() bool { conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", ip, daemonPort)) if err != nil { - fmt.Println("Got an error it was", err) + log.Debug("Got an error it was", err) return false } conn.Close()