@@ -257,16 +257,6 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
257257 return nil
258258 }
259259
260- _ , restartPolicyExist := lab [restart .PolicyLabel ]
261- if restartPolicyExist {
262- if err := UpdateStatusLabel (ctx , container , containerd .Running ); err != nil {
263- return err
264- }
265- }
266-
267- if err := UpdateExplicitlyStoppedLabel (ctx , container , false ); err != nil {
268- return err
269- }
270260 if oldTask , err := container .Task (ctx , nil ); err == nil {
271261 if _ , err := oldTask .Delete (ctx ); err != nil {
272262 log .G (ctx ).WithError (err ).Debug ("failed to delete old task" )
@@ -302,6 +292,17 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
302292 return err
303293 }
304294
295+ // restart label should call after task is started.
296+ _ , restartPolicyExist := lab [restart .PolicyLabel ]
297+ if restartPolicyExist {
298+ if err := UpdateStatusLabel (ctx , container , containerd .Running ); err != nil {
299+ return err
300+ }
301+ }
302+ if err := UpdateExplicitlyStoppedLabel (ctx , container , false ); err != nil {
303+ return err
304+ }
305+
305306 // If container has health checks configured, create and start systemd timer/service files.
306307 if err := healthcheck .CreateTimer (ctx , container , cfg , nerdctlCmd , nerdctlArgs ); err != nil {
307308 return fmt .Errorf ("failed to create healthcheck timer: %w" , err )
0 commit comments