Not adding the docker check if we couldn't create the client

pull/1343/head
Diptanu Choudhury 2015-10-26 16:45:12 -07:00
parent f5f5ed0c79
commit 423f7fbcac
2 changed files with 15 additions and 9 deletions

View File

@ -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 {

View File

@ -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()