@@ -304,13 +304,15 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
304304 }
305305
306306 // If container has health checks configured, create and start systemd timer/service files.
307- if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs ); err != nil {
308- return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
309- }
310- if err := healthcheck .StartTimer (ctx , container , cfg ); err != nil {
311- return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
307+ if hcStr , ok := lab [labels .HealthCheck ]; ok && hcStr != "" {
308+ // If container has health checks configured, create and start systemd timer/service files.
309+ if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs , lab ); err != nil {
310+ return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
311+ }
312+ if err := healthcheck .StartTimer (ctx , container , cfg , lab ); err != nil {
313+ return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
314+ }
312315 }
313-
314316 if ! isAttach {
315317 return nil
316318 }
@@ -542,12 +544,19 @@ func Unpause(ctx context.Context, client *containerd.Client, id string, cfg *con
542544 return err
543545 }
544546
545- // Recreate healthcheck related systemd timer/service files.
546- if err := healthcheck . CreateTimer ( ctx , container , cfg , nerdctlCmd , nerdctlArgs ); err != nil {
547- return fmt . Errorf ( "failed to create healthcheck timer: %w" , err )
547+ label , err := container . Labels ( ctx )
548+ if err != nil {
549+ return err
548550 }
549- if err := healthcheck .StartTimer (ctx , container , cfg ); err != nil {
550- return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
551+
552+ if hcStr , ok := label [labels .HealthCheck ]; ok && hcStr != "" {
553+ // Recreate healthcheck related systemd timer/service files.
554+ if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs , label ); err != nil {
555+ return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
556+ }
557+ if err := healthcheck .StartTimer (ctx , container , cfg , label ); err != nil {
558+ return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
559+ }
551560 }
552561
553562 switch status .Status {
0 commit comments