Extracted the logic of figuring out the shell and fixing the logic to find out if the check is a Docker check

This commit is contained in:
Diptanu Choudhury 2015-10-26 15:00:34 -07:00
parent 31cdf4fe64
commit 809e9f5284
1 changed files with 12 additions and 10 deletions

View File

@ -82,7 +82,7 @@ func (c *CheckType) IsTCP() bool {
}
func (c *CheckType) IsDocker() bool {
return c.DockerContainerId != "" && c.Shell != "" && c.Interval != 0
return c.DockerContainerId != "" && c.Interval != 0
}
// CheckNotifier interface is used by the CheckMonitor
@ -547,11 +547,7 @@ func (c *CheckDocker) Start() {
//figure out the shell
if c.Shell == "" {
if otherShell := os.Getenv("SHELL"); otherShell != "" {
c.Shell = otherShell
} else {
c.Shell = "/bin/sh"
}
c.Shell = shell()
}
c.cmd = []string{c.Shell, "-c", c.Script}
@ -602,9 +598,7 @@ func (c *CheckDocker) check() {
exec *docker.Exec
err error
)
if exec, err = c.dockerClient.CreateExec(execOpts); err == nil {
exec = exec
} else {
if exec, err = c.dockerClient.CreateExec(execOpts); err != nil {
c.Logger.Printf("[DEBUG] agent: Error while creating Exec: %s", err.Error())
c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, fmt.Sprintf("Unable to create Exec, error: %s", err.Error()))
return
@ -613,7 +607,7 @@ func (c *CheckDocker) check() {
err = c.dockerClient.StartExec(exec.ID, docker.StartExecOptions{Detach: false, Tty: false})
if err != nil {
c.Logger.Printf("[DEBUG] Error in executing health checks: %s", err.Error())
c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, fmt.Sprintf("Unable to start exec: %s", err.Error()))
c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, fmt.Sprintf("Unable to start Exec: %s", err.Error()))
return
}
@ -632,3 +626,11 @@ func (c *CheckDocker) check() {
}
}
func shell() string {
if otherShell := os.Getenv("SHELL"); otherShell != "" {
return otherShell
} else {
return "/bin/sh"
}
}