@@ -307,26 +307,34 @@ func (c *Connection) ExecScript(script string) ([]byte, error) {
307307}
308308
309309// Healthcheck runs healthcheck command inside the container.
310- func (c * Connection ) Healthcheck () ([] byte , error ) {
310+ func (c * Connection ) Healthcheck () error {
311311 if c .podName == "" {
312312 if _ , err := c .GetPodName (); c .podName == "" {
313- return nil , utils .Errorf (err , L ("Healthcheck not executed" ))
313+ return utils .Errorf (err , L ("Healthcheck not executed" ))
314314 }
315315 }
316316
317317 cmd , cmdErr := c .GetCommand ()
318318 if cmdErr != nil {
319- return nil , cmdErr
319+ return cmdErr
320320 }
321321
322322 if cmd == "host" {
323323 // Healthcheck not supported on host, always return nil
324- return nil , nil
324+ return nil
325325 }
326326
327- cmdArgs := []string {"healthcheck " , "run " , c .podName }
327+ cmdArgs := []string {"inspect " , "--format" , "{{ .State.Health.Status }} " , c .podName }
328328
329- return runner (cmd , cmdArgs ... ).Log (zerolog .DebugLevel ).Spinner ("" ).Exec ()
329+ out , err := runner (cmd , cmdArgs ... ).Log (zerolog .DebugLevel ).Spinner ("" ).Exec ()
330+ if err != nil {
331+ return err
332+ }
333+ outStr := strings .TrimSpace (string (out ))
334+ if outStr != "healthy" && outStr != "running" {
335+ return errors .New (L ("not healthy or running" ))
336+ }
337+ return nil
330338}
331339
332340// WaitForContainer waits up to 10 sec for the container to appear.
@@ -380,7 +388,7 @@ func (c *Connection) WaitForHealthcheck() error {
380388 }
381389 // once here, container started at least once, clear startupTimeout
382390 startupTimeout = 0
383- _ , err := c .Healthcheck ()
391+ err := c .Healthcheck ()
384392 if err != nil {
385393 log .Debug ().Err (err )
386394 time .Sleep (1 * time .Second )
0 commit comments