pause and resume multi-containers

With this patch, `runc pasue` and `runc resume` can
pause and resume multi-containers.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
This commit is contained in:
Wang Long
2016-09-24 13:25:13 +00:00
parent a6284a7bdb
commit 2f5c0afbbc
4 changed files with 132 additions and 11 deletions
+52 -9
View File
@@ -2,12 +2,17 @@
package main
import "github.com/urfave/cli"
import (
"fmt"
"os"
"github.com/urfave/cli"
)
var pauseCommand = cli.Command{
Name: "pause",
Usage: "pause suspends all processes inside the container",
ArgsUsage: `<container-id>
ArgsUsage: `<container-id> [container-id...]
Where "<container-id>" is the name for the instance of the container to be
paused. `,
@@ -15,12 +20,31 @@ paused. `,
Use runc list to identiy instances of containers and their current status.`,
Action: func(context *cli.Context) error {
container, err := getContainer(context)
hasError := false
if !context.Args().Present() {
return fmt.Errorf("runc: \"pause\" requires a minimum of 1 argument")
}
factory, err := loadFactory(context)
if err != nil {
return err
}
if err := container.Pause(); err != nil {
return err
for _, id := range context.Args() {
container, err := factory.Load(id)
if err != nil {
fmt.Fprintf(os.Stderr, "container %s is not exist\n", id)
hasError = true
continue
}
if err := container.Pause(); err != nil {
fmt.Fprintf(os.Stderr, "pause container %s : %s\n", id, err)
hasError = true
}
}
if hasError {
return fmt.Errorf("one or more of container pause failed")
}
return nil
},
@@ -29,7 +53,7 @@ Use runc list to identiy instances of containers and their current status.`,
var resumeCommand = cli.Command{
Name: "resume",
Usage: "resumes all processes that have been previously paused",
ArgsUsage: `<container-id>
ArgsUsage: `<container-id> [container-id...]
Where "<container-id>" is the name for the instance of the container to be
resumed.`,
@@ -37,12 +61,31 @@ resumed.`,
Use runc list to identiy instances of containers and their current status.`,
Action: func(context *cli.Context) error {
container, err := getContainer(context)
hasError := false
if !context.Args().Present() {
return fmt.Errorf("runc: \"resume\" requires a minimum of 1 argument")
}
factory, err := loadFactory(context)
if err != nil {
return err
}
if err := container.Resume(); err != nil {
return err
for _, id := range context.Args() {
container, err := factory.Load(id)
if err != nil {
fmt.Fprintf(os.Stderr, "container %s is not exist\n", id)
hasError = true
continue
}
if err := container.Resume(); err != nil {
fmt.Fprintf(os.Stderr, "resume container %s : %s\n", id, err)
hasError = true
}
}
if hasError {
return fmt.Errorf("one or more of container resume failed")
}
return nil
},