Browse code

Merge pull request #4684 from cpuguy83/4682-do_not_sigkill_on_docker_stop

Disable automatic killing of containers when docker stop fails

Guillaume J. Charmes authored on 2014/03/19 03:28:42
Showing 4 changed files
... ...
@@ -497,8 +497,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
497 497
 }
498 498
 
499 499
 func (cli *DockerCli) CmdStop(args ...string) error {
500
-	cmd := cli.Subcmd("stop", "[OPTIONS] CONTAINER [CONTAINER...]", "Stop a running container (Send SIGTERM, and then SIGKILL after grace period)")
501
-	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop before killing it.")
500
+	cmd := cli.Subcmd("stop", "[OPTIONS] CONTAINER [CONTAINER...]", "Stop a running container (Send SIGTERM)")
501
+	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop.")
502 502
 	if err := cmd.Parse(args); err != nil {
503 503
 		return nil
504 504
 	}
... ...
@@ -525,7 +525,7 @@ func (cli *DockerCli) CmdStop(args ...string) error {
525 525
 
526 526
 func (cli *DockerCli) CmdRestart(args ...string) error {
527 527
 	cmd := cli.Subcmd("restart", "[OPTIONS] CONTAINER [CONTAINER...]", "Restart a running container")
528
-	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default=10")
528
+	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop. Default=10")
529 529
 	if err := cmd.Parse(args); err != nil {
530 530
 		return nil
531 531
 	}
... ...
@@ -432,7 +432,7 @@ Stop a container
432 432
 
433 433
            HTTP/1.1 204 OK
434 434
 
435
-        :query t: number of seconds to wait before killing the container
435
+        :query t: number of seconds to wait for the container to stop
436 436
         :statuscode 204: no error
437 437
         :statuscode 404: no such container
438 438
         :statuscode 500: server error
... ...
@@ -457,7 +457,7 @@ Restart a container
457 457
 
458 458
            HTTP/1.1 204 OK
459 459
 
460
-        :query t: number of seconds to wait before killing the container
460
+        :query t: number of seconds to wait for the container to stop
461 461
         :statuscode 204: no error
462 462
         :statuscode 404: no such container
463 463
         :statuscode 500: server error
... ...
@@ -1371,11 +1371,11 @@ This example shows 5 containers that might be set up to test a web application c
1371 1371
 
1372 1372
     Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
1373 1373
 
1374
-    Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
1374
+    Stop a running container (Send SIGTERM)
1375 1375
 
1376
-      -t, --time=10: Number of seconds to wait for the container to stop before killing it.
1376
+      -t, --time=10: Number of seconds to wait for the container to stop.
1377 1377
 
1378
-The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
1378
+The main process inside the container will receive SIGTERM.
1379 1379
 
1380 1380
 .. _cli_tag:
1381 1381
 
... ...
@@ -906,20 +906,12 @@ func (container *Container) Stop(seconds int) error {
906 906
 
907 907
 	// 1. Send a SIGTERM
908 908
 	if err := container.KillSig(15); err != nil {
909
-		utils.Debugf("Error sending kill SIGTERM: %s", err)
910
-		log.Print("Failed to send SIGTERM to the process, force killing")
911
-		if err := container.KillSig(9); err != nil {
912
-			return err
913
-		}
909
+		return err
914 910
 	}
915 911
 
916 912
 	// 2. Wait for the process to exit on its own
917 913
 	if err := container.WaitTimeout(time.Duration(seconds) * time.Second); err != nil {
918
-		log.Printf("Container %v failed to exit within %d seconds of SIGTERM - using the force", container.ID, seconds)
919
-		// 3. If it doesn't, then send SIGKILL
920
-		if err := container.Kill(); err != nil {
921
-			return err
922
-		}
914
+		return err
923 915
 	}
924 916
 	return nil
925 917
 }