Merge pull request #2798 from lifubang/execd

add flag -d for ctr t exec to run a service in container
This commit is contained in:
Phil Estes 2018-11-20 08:34:29 +08:00 committed by GitHub
commit 55baf50b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,10 @@ var execCommand = cli.Command{
Name: "tty,t", Name: "tty,t",
Usage: "allocate a TTY for the container", Usage: "allocate a TTY for the container",
}, },
cli.BoolFlag{
Name: "detach,d",
Usage: "detach from the task after it has started execution",
},
cli.StringFlag{ cli.StringFlag{
Name: "exec-id", Name: "exec-id",
Usage: "exec specific id for the process", Usage: "exec specific id for the process",
@ -51,9 +55,10 @@ var execCommand = cli.Command{
}, },
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
var ( var (
id = context.Args().First() id = context.Args().First()
args = context.Args().Tail() args = context.Args().Tail()
tty = context.Bool("tty") tty = context.Bool("tty")
detach = context.Bool("detach")
) )
if id == "" { if id == "" {
return errors.New("container id must be provided") return errors.New("container id must be provided")
@ -104,18 +109,23 @@ var execCommand = cli.Command{
return err return err
} }
} }
if tty { if !detach {
if err := HandleConsoleResize(ctx, process, con); err != nil { if tty {
logrus.WithError(err).Error("console resize") if err := HandleConsoleResize(ctx, process, con); err != nil {
logrus.WithError(err).Error("console resize")
}
} else {
sigc := commands.ForwardAllSignals(ctx, process)
defer commands.StopCatch(sigc)
} }
} else {
sigc := commands.ForwardAllSignals(ctx, process)
defer commands.StopCatch(sigc)
} }
if err := process.Start(ctx); err != nil { if err := process.Start(ctx); err != nil {
return err return err
} }
if detach {
return nil
}
status := <-statusC status := <-statusC
code, _, err := status.Result() code, _, err := status.Result()
if err != nil { if err != nil {