@@ -292,6 +292,16 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
292292 return err
293293 }
294294
295+ if hcStr , ok := lab [labels .HealthCheck ]; ok && hcStr != "" {
296+ // If container has health checks configured, create and start systemd timer/service files.
297+ if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs , lab ); err != nil {
298+ return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
299+ }
300+ if err := healthcheck .StartTimer (ctx , container , cfg , lab ); err != nil {
301+ return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
302+ }
303+ }
304+
295305 // Set status label running should call after task is started.
296306 _ , restartPolicyExist := lab [restart .PolicyLabel ]
297307 if restartPolicyExist {
@@ -303,14 +313,6 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
303313 return err
304314 }
305315
306- // 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 )
312- }
313-
314316 if ! isAttach {
315317 return nil
316318 }
@@ -542,12 +544,20 @@ 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+ hcStr , ok := label [labels .HealthCheck ]
553+ if ! ok || hcStr == "" {
554+ // Recreate healthcheck related systemd timer/service files.
555+ if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs , label ); err != nil {
556+ return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
557+ }
558+ if err := healthcheck .StartTimer (ctx , container , cfg , label ); err != nil {
559+ return fmt .Errorf ("failed to start healthcheck timer: %w" , err )
560+ }
551561 }
552562
553563 switch status .Status {
0 commit comments