github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podmanV2/healthcheck/run.go (about)

     1  package healthcheck
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/containers/libpod/cmd/podmanV2/registry"
     8  	"github.com/containers/libpod/pkg/domain/entities"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  var (
    13  	healthcheckRunDescription = "run the health check of a container"
    14  	healthcheckrunCommand     = &cobra.Command{
    15  		Use:     "run [flags] CONTAINER",
    16  		Short:   "run the health check of a container",
    17  		Long:    healthcheckRunDescription,
    18  		Example: `podman healthcheck run mywebapp`,
    19  		RunE:    run,
    20  		Args:    cobra.ExactArgs(1),
    21  	}
    22  )
    23  
    24  func init() {
    25  	registry.Commands = append(registry.Commands, registry.CliCommand{
    26  		Mode:    []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
    27  		Command: healthcheckrunCommand,
    28  		Parent:  healthCmd,
    29  	})
    30  }
    31  
    32  func run(cmd *cobra.Command, args []string) error {
    33  	response, err := registry.ContainerEngine().HealthCheckRun(context.Background(), args[0], entities.HealthCheckOptions{})
    34  	if err != nil {
    35  		return err
    36  	}
    37  	if response.Status == "unhealthy" {
    38  		registry.SetExitCode(1)
    39  	}
    40  	fmt.Println(response.Status)
    41  	return err
    42  }