2017-02-01 00:45:59 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2017-02-06 20:16:36 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
var pauseCommand = cli.Command{
|
|
|
|
Name: "pause",
|
|
|
|
Usage: "pause suspends all processes inside the container",
|
2017-02-06 20:16:36 +00:00
|
|
|
ArgsUsage: `<container-id> [container-id...]
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
Where "<container-id>" is the name for the instance of the container to be
|
|
|
|
paused. `,
|
|
|
|
Description: `The pause command suspends all processes in the instance of the container.
|
|
|
|
|
|
|
|
Use runc list to identiy instances of containers and their current status.`,
|
2017-02-06 20:16:36 +00:00
|
|
|
Action: func(context *cli.Context) error {
|
|
|
|
if err := checkArgs(context, 1, minArgs); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hasError := false
|
|
|
|
factory, err := loadFactory(context)
|
2017-02-01 00:45:59 +00:00
|
|
|
if err != nil {
|
2017-02-06 20:16:36 +00:00
|
|
|
return err
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-02-06 20:16:36 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
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")
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-02-06 20:16:36 +00:00
|
|
|
return nil
|
2017-02-01 00:45:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resumeCommand = cli.Command{
|
|
|
|
Name: "resume",
|
|
|
|
Usage: "resumes all processes that have been previously paused",
|
2017-02-06 20:16:36 +00:00
|
|
|
ArgsUsage: `<container-id> [container-id...]
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
Where "<container-id>" is the name for the instance of the container to be
|
|
|
|
resumed.`,
|
|
|
|
Description: `The resume command resumes all processes in the instance of the container.
|
|
|
|
|
|
|
|
Use runc list to identiy instances of containers and their current status.`,
|
2017-02-06 20:16:36 +00:00
|
|
|
Action: func(context *cli.Context) error {
|
|
|
|
if err := checkArgs(context, 1, minArgs); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hasError := false
|
|
|
|
factory, err := loadFactory(context)
|
2017-02-01 00:45:59 +00:00
|
|
|
if err != nil {
|
2017-02-06 20:16:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
if err := container.Resume(); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "resume container %s : %s\n", id, err)
|
|
|
|
hasError = true
|
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-02-06 20:16:36 +00:00
|
|
|
|
|
|
|
if hasError {
|
|
|
|
return fmt.Errorf("one or more of container resume failed")
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-02-06 20:16:36 +00:00
|
|
|
return nil
|
2017-02-01 00:45:59 +00:00
|
|
|
},
|
|
|
|
}
|