Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crictl stop: enable timeout #133

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ var stopContainerCommand = cli.Command{
Name: "stop",
Usage: "Stop a running container",
ArgsUsage: "CONTAINER",
Flags: []cli.Flag{
cli.Int64Flag{
Name: "timeout, t",
Value: 10,
Usage: "Seconds to wait to kill the container after a graceful stop is requested",
},
},
Action: func(context *cli.Context) error {
containerID := context.Args().First()
if containerID == "" {
Expand All @@ -104,7 +111,7 @@ var stopContainerCommand = cli.Command{
return err
}

err := StopContainer(runtimeClient, containerID)
err := StopContainer(runtimeClient, containerID, context.Int64("timeout"))
if err != nil {
return fmt.Errorf("Stopping the container failed: %v", err)
}
Expand Down Expand Up @@ -280,12 +287,13 @@ func StartContainer(client pb.RuntimeServiceClient, ID string) error {

// StopContainer sends a StopContainerRequest to the server, and parses
// the returned StopContainerResponse.
func StopContainer(client pb.RuntimeServiceClient, ID string) error {
func StopContainer(client pb.RuntimeServiceClient, ID string, timeout int64) error {
if ID == "" {
return fmt.Errorf("ID cannot be empty")
}
request := &pb.StopContainerRequest{
ContainerId: ID,
Timeout: timeout,
}
logrus.Debugf("StopContainerRequest: %v", request)
r, err := client.StopContainer(context.Background(), request)
Expand Down