Files
podman/cmd/podman/healthcheck_run.go
baude 03716cf7f3 healtcheck phase 2
integration of healthcheck into create and run as well as inspect.
healthcheck enhancements are as follows:

* add the following options to create|run so that non-docker images can
define healthchecks at the container level.
  * --healthcheck-command
  * --healthcheck-retries
  * --healthcheck-interval
  * --healthcheck-start-period

* podman create|run --healthcheck-command=none disables healthcheck as
described by an image.
* the healthcheck itself and the healthcheck "history" can now be
observed in podman inspect
* added the wiring for healthcheck history which logs the health history
of the container, the current failed streak attempts, and log entries
for the last five attempts which themselves have start and stop times,
result, and a 500 character truncated (if needed) log of stderr/stdout.

The timings themselves are not implemented in this PR but will be in
future enablement (i.e. next).

Signed-off-by: baude <bbaude@redhat.com>
2019-03-12 14:29:18 -05:00

54 lines
1.4 KiB
Go

package main
import (
"fmt"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var (
healthcheckRunCommand cliconfig.HealthCheckValues
healthcheckRunDescription = "run the health check of a container"
_healthcheckrunCommand = &cobra.Command{
Use: "run [flags] CONTAINER",
Short: "run the health check of a container",
Long: healthcheckRunDescription,
Example: `podman healthcheck run mywebapp`,
RunE: func(cmd *cobra.Command, args []string) error {
healthcheckRunCommand.InputArgs = args
healthcheckRunCommand.GlobalFlags = MainGlobalOpts
return healthCheckCmd(&healthcheckRunCommand)
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 || len(args) > 1 {
return errors.New("must provide the name or ID of one container")
}
return nil
},
}
)
func init() {
healthcheckRunCommand.Command = _healthcheckrunCommand
healthcheckRunCommand.SetUsageTemplate(UsageTemplate())
}
func healthCheckCmd(c *cliconfig.HealthCheckValues) error {
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrap(err, "could not get runtime")
}
status, err := runtime.HealthCheck(c)
if err != nil {
if status == libpod.HealthCheckFailure {
fmt.Println("\nunhealthy")
}
return err
}
fmt.Println("healthy")
return nil
}