Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
fixes #229: wait for docker before adding to known_hosts
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
  • Loading branch information
ehazlett committed Jan 12, 2015
1 parent 4c285dc commit 8d40d82
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ func (d *Driver) Create() error {
return err
}

cmd, err = d.GetSSHCommand("if [ -e /var/run/docker.pid ]; then sudo /etc/init.d/docker stop; fi")
if err != nil {
return err
}
if err := cmd.Run(); err != nil {
return err
}

// HACK: configure docker to use persisted auth
cmd, err = d.GetSSHCommand("echo DOCKER_TLS=no | sudo tee -a /var/lib/boot2docker/profile")
if err != nil {
Expand All @@ -355,7 +363,7 @@ func (d *Driver) Create() error {
return err
}

cmd, err = d.GetSSHCommand("sudo /etc/init.d/docker restart")
cmd, err = d.GetSSHCommand("sudo /etc/init.d/docker start")
if err != nil {
return err
}
Expand Down
18 changes: 18 additions & 0 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -33,6 +34,19 @@ type hostConfig struct {
DriverName string
}

func waitForDocker(addr string) error {
for {
conn, err := net.DialTimeout("tcp", addr, time.Second*5)
if err != nil {
time.Sleep(time.Second * 5)
continue
}
conn.Close()
break
}
return nil
}

func NewHost(name, driverName, storePath string) (*Host, error) {
driver, err := drivers.NewDriver(driverName, storePath)
if err != nil {
Expand Down Expand Up @@ -156,6 +170,10 @@ func (h *Host) addHostToKnownHosts() error {

tlsConfig.InsecureSkipVerify = true

log.Debugf("waiting for Docker to become available on %s", addr)
if err := waitForDocker(addr); err != nil {

This comment has been minimized.

Copy link
@nathanleclaire

nathanleclaire Jan 14, 2015

Contributor

In the current code there will never be an error returned - I'd add e.g. a maxRetries or not bother at all.

This comment has been minimized.

Copy link
@ehazlett

ehazlett Jan 14, 2015

Author Contributor

Good catch. Thanks.

return fmt.Errorf("unable to connect to Docker daemon: %s", err)
}
testConn, err := tls.Dial(proto, addr, tlsConfig)
if err != nil {
return fmt.Errorf("tls Handshake error: %s", err)
Expand Down

0 comments on commit 8d40d82

Please sign in to comment.