Skip to content

Commit df88790

Browse files
authored
Merge pull request #133 from sak0/dev
crictl stop: enable timeout
2 parents 3816481 + 6f4d0c4 commit df88790

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/crictl/container.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ var stopContainerCommand = cli.Command{
9494
Name: "stop",
9595
Usage: "Stop a running container",
9696
ArgsUsage: "CONTAINER",
97+
Flags: []cli.Flag{
98+
cli.Int64Flag{
99+
Name: "timeout, t",
100+
Value: 10,
101+
Usage: "Seconds to wait to kill the container after a graceful stop is requested",
102+
},
103+
},
97104
Action: func(context *cli.Context) error {
98105
containerID := context.Args().First()
99106
if containerID == "" {
@@ -104,7 +111,7 @@ var stopContainerCommand = cli.Command{
104111
return err
105112
}
106113

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

281288
// StopContainer sends a StopContainerRequest to the server, and parses
282289
// the returned StopContainerResponse.
283-
func StopContainer(client pb.RuntimeServiceClient, ID string) error {
290+
func StopContainer(client pb.RuntimeServiceClient, ID string, timeout int64) error {
284291
if ID == "" {
285292
return fmt.Errorf("ID cannot be empty")
286293
}
287294
request := &pb.StopContainerRequest{
288295
ContainerId: ID,
296+
Timeout: timeout,
289297
}
290298
logrus.Debugf("StopContainerRequest: %v", request)
291299
r, err := client.StopContainer(context.Background(), request)

0 commit comments

Comments
 (0)