add -detach flag for 'ctr t start'
Signed-off-by: Lifubang <lifubang@aliyun.com>
This commit is contained in:
parent
830363acac
commit
66f6dd8b3b
@ -18,6 +18,7 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -42,11 +43,16 @@ var startCommand = cli.Command{
|
|||||||
Name: "pid-file",
|
Name: "pid-file",
|
||||||
Usage: "file path to write the task's pid",
|
Usage: "file path to write the task's pid",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "detach,d",
|
||||||
|
Usage: "detach from the task after it has started execution",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
id = context.Args().Get(0)
|
id = context.Args().Get(0)
|
||||||
|
detach = context.Bool("detach")
|
||||||
)
|
)
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("container id must be provided")
|
return errors.New("container id must be provided")
|
||||||
@ -83,20 +89,25 @@ var startCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
var statusC <-chan containerd.ExitStatus
|
||||||
|
if !detach {
|
||||||
|
defer task.Delete(ctx)
|
||||||
|
if statusC, err = task.Wait(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if context.IsSet("pid-file") {
|
if context.IsSet("pid-file") {
|
||||||
if err := commands.WritePidFile(context.String("pid-file"), int(task.Pid())); err != nil {
|
if err := commands.WritePidFile(context.String("pid-file"), int(task.Pid())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statusC, err := task.Wait(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if detach {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if tty {
|
if tty {
|
||||||
if err := HandleConsoleResize(ctx, task, con); err != nil {
|
if err := HandleConsoleResize(ctx, task, con); err != nil {
|
||||||
logrus.WithError(err).Error("console resize")
|
logrus.WithError(err).Error("console resize")
|
||||||
|
Loading…
Reference in New Issue
Block a user