mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Only allow single container operation
As per the discussions in #1156 , we think it's a bad idea to allow multi container operations in runc. So revert it. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
"github.com/urfave/cli"
|
||||
@@ -11,56 +11,33 @@ import (
|
||||
var startCommand = cli.Command{
|
||||
Name: "start",
|
||||
Usage: "executes the user defined process in a created container",
|
||||
ArgsUsage: `<container-id> [container-id...]
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container that you
|
||||
are starting. The name you provide for the container instance must be unique on
|
||||
your host.`,
|
||||
Description: `The start command executes the user defined process in a created container .`,
|
||||
Description: `The start command executes the user defined process in a created container.`,
|
||||
Action: func(context *cli.Context) error {
|
||||
if err := checkArgs(context, 1, minArgs); err != nil {
|
||||
if err := checkArgs(context, 1, exactArgs); err != nil {
|
||||
return err
|
||||
}
|
||||
hasError := false
|
||||
factory, err := loadFactory(context)
|
||||
container, err := getContainer(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, id := range context.Args() {
|
||||
container, err := factory.Load(id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "container %s does not exist\n", id)
|
||||
hasError = true
|
||||
continue
|
||||
}
|
||||
status, err := container.Status()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "status for %s: %v\n", id, err)
|
||||
hasError = true
|
||||
continue
|
||||
}
|
||||
switch status {
|
||||
case libcontainer.Created:
|
||||
if err := container.Exec(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "start for %s failed: %v\n", id, err)
|
||||
hasError = true
|
||||
}
|
||||
case libcontainer.Stopped:
|
||||
fmt.Fprintln(os.Stderr, "cannot start a container that has stopped")
|
||||
hasError = true
|
||||
case libcontainer.Running:
|
||||
fmt.Fprintln(os.Stderr, "cannot start an already running container")
|
||||
hasError = true
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "cannot start a container in the %s state\n", status)
|
||||
hasError = true
|
||||
}
|
||||
status, err := container.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if hasError {
|
||||
return fmt.Errorf("one or more of container start failed")
|
||||
switch status {
|
||||
case libcontainer.Created:
|
||||
return container.Exec()
|
||||
case libcontainer.Stopped:
|
||||
return errors.New("cannot start a container that has stopped")
|
||||
case libcontainer.Running:
|
||||
return errors.New("cannot start an already running container")
|
||||
default:
|
||||
return fmt.Errorf("cannot start a container in the %s state\n", status)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user