@@ -18,6 +18,7 @@ package tasks
1818
1919import (
2020 "github.com/containerd/console"
21+ "github.com/containerd/containerd"
2122 "github.com/containerd/containerd/cio"
2223 "github.com/containerd/containerd/cmd/ctr/commands"
2324 "github.com/pkg/errors"
@@ -42,11 +43,16 @@ var startCommand = cli.Command{
4243 Name : "pid-file" ,
4344 Usage : "file path to write the task's pid" ,
4445 },
46+ cli.BoolFlag {
47+ Name : "detach,d" ,
48+ Usage : "detach from the task after it has started execution" ,
49+ },
4550 },
4651 Action : func (context * cli.Context ) error {
4752 var (
48- err error
49- id = context .Args ().Get (0 )
53+ err error
54+ id = context .Args ().Get (0 )
55+ detach = context .Bool ("detach" )
5056 )
5157 if id == "" {
5258 return errors .New ("container id must be provided" )
@@ -83,20 +89,25 @@ var startCommand = cli.Command{
8389 if err != nil {
8490 return err
8591 }
86- defer task .Delete (ctx )
92+ var statusC <- chan containerd.ExitStatus
93+ if ! detach {
94+ defer task .Delete (ctx )
95+ if statusC , err = task .Wait (ctx ); err != nil {
96+ return err
97+ }
98+ }
8799 if context .IsSet ("pid-file" ) {
88100 if err := commands .WritePidFile (context .String ("pid-file" ), int (task .Pid ())); err != nil {
89101 return err
90102 }
91103 }
92- statusC , err := task .Wait (ctx )
93- if err != nil {
94- return err
95- }
96104
97105 if err := task .Start (ctx ); err != nil {
98106 return err
99107 }
108+ if detach {
109+ return nil
110+ }
100111 if tty {
101112 if err := HandleConsoleResize (ctx , task , con ); err != nil {
102113 logrus .WithError (err ).Error ("console resize" )
0 commit comments