mirror of
https://github.com/containers/podman.git
synced 2025-06-09 17:07:51 +08:00
healthcheck: improve command list parser
- remove duplicate check, already called in HealthCheck() - reject zero-length command list and empty command string as errorneous - support all Docker command list keywords: NONE, CMD or CMD-SHELL - use Docker default "/bin/sh -c" for CMD-SHELL Fixes #3507 Signed-off-by: Stefan Becker <chemobejk@gmail.com>
This commit is contained in:
@ -107,14 +107,20 @@ func (c *Container) runHealthCheck() (HealthCheckStatus, error) {
|
|||||||
capture bytes.Buffer
|
capture bytes.Buffer
|
||||||
inStartPeriod bool
|
inStartPeriod bool
|
||||||
)
|
)
|
||||||
hcStatus, err := checkHealthCheckCanBeRun(c)
|
|
||||||
if err != nil {
|
|
||||||
return hcStatus, err
|
|
||||||
}
|
|
||||||
hcCommand := c.HealthCheckConfig().Test
|
hcCommand := c.HealthCheckConfig().Test
|
||||||
if len(hcCommand) > 0 && hcCommand[0] == "CMD-SHELL" {
|
if len(hcCommand) < 1 {
|
||||||
newCommand = []string{"sh", "-c", strings.Join(hcCommand[1:], " ")}
|
return HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
||||||
} else {
|
}
|
||||||
|
switch hcCommand[0] {
|
||||||
|
case "", "NONE":
|
||||||
|
return HealthCheckNotDefined, errors.Errorf("container %s has no defined healthcheck", c.ID())
|
||||||
|
case "CMD":
|
||||||
|
newCommand = hcCommand[1:]
|
||||||
|
case "CMD-SHELL":
|
||||||
|
// TODO: SHELL command from image not available in Container - use Docker default
|
||||||
|
newCommand = []string{"/bin/sh", "-c", strings.Join(hcCommand[1:], " ")}
|
||||||
|
default:
|
||||||
|
// command supplied on command line - pass as-is
|
||||||
newCommand = hcCommand
|
newCommand = hcCommand
|
||||||
}
|
}
|
||||||
captureBuffer := bufio.NewWriter(&capture)
|
captureBuffer := bufio.NewWriter(&capture)
|
||||||
|
Reference in New Issue
Block a user