diff --git a/command/agent/agent.go b/command/agent/agent.go index f36294b151..58911856f7 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -928,6 +928,9 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType, persist Interval: chkType.Interval, Logger: a.logger, } + if err := dockerCheck.Init(); err != nil { + return err + } dockerCheck.Start() a.checkDockers[check.CheckID] = dockerCheck } else { diff --git a/command/agent/check.go b/command/agent/check.go index 884e0ab12a..8ca3e3cc61 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -530,21 +530,24 @@ type CheckDocker struct { stopLock sync.Mutex } +//Initializes the Docker Client +func (c *CheckDocker) Init() error { + //create the docker client + var err error + c.dockerClient, err = docker.NewClientFromEnv() + if err != nil { + c.Logger.Println("[DEBUG] Error creating the Docker Client : %s", err.Error()) + return err + } + return nil +} + // Start is used to start checks. // Docker Checks runs until stop is called func (c *CheckDocker) Start() { c.stopLock.Lock() defer c.stopLock.Unlock() - //create the docker client - if c.dockerClient == nil { - var err error - c.dockerClient, err = docker.NewClientFromEnv() - if err != nil { - c.Logger.Println("[DEBUG] Error creating the Docker Client : %s", err.Error()) - } - } - //figure out the shell if c.Shell == "" { c.Shell = shell()