github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/api/handlers/libpod/healthcheck.go (about) 1 package libpod 2 3 import ( 4 "net/http" 5 6 "github.com/containers/libpod/libpod" 7 "github.com/containers/libpod/pkg/api/handlers/utils" 8 ) 9 10 func RunHealthCheck(w http.ResponseWriter, r *http.Request) { 11 runtime := r.Context().Value("runtime").(*libpod.Runtime) 12 name := utils.GetName(r) 13 status, err := runtime.HealthCheck(name) 14 if err != nil { 15 if status == libpod.HealthCheckContainerNotFound { 16 utils.ContainerNotFound(w, name, err) 17 return 18 } 19 if status == libpod.HealthCheckNotDefined { 20 utils.Error(w, "no healthcheck defined", http.StatusConflict, err) 21 return 22 } 23 if status == libpod.HealthCheckContainerStopped { 24 utils.Error(w, "container not running", http.StatusConflict, err) 25 return 26 } 27 utils.InternalServerError(w, err) 28 return 29 } 30 ctr, err := runtime.LookupContainer(name) 31 if err != nil { 32 utils.InternalServerError(w, err) 33 return 34 } 35 36 hcLog, err := ctr.GetHealthCheckLog() 37 if err != nil { 38 utils.InternalServerError(w, err) 39 return 40 } 41 42 utils.WriteResponse(w, http.StatusOK, hcLog) 43 }