Przeglądaj źródła

Merge pull request #4835 from crosbymichael/reverst-stop-kill

Revert back to the default stop functionality of SIGKILL after timeout
Guillaume J. Charmes 11 lat temu
rodzic
commit
c3ff1f41bb

+ 3 - 3
api/client.go

@@ -498,8 +498,8 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
 }
 }
 
 
 func (cli *DockerCli) CmdStop(args ...string) error {
 func (cli *DockerCli) CmdStop(args ...string) error {
-	cmd := cli.Subcmd("stop", "[OPTIONS] CONTAINER [CONTAINER...]", "Stop a running container (Send SIGTERM)")
-	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop.")
+	cmd := cli.Subcmd("stop", "[OPTIONS] CONTAINER [CONTAINER...]", "Stop a running container (Send SIGTERM, and then SIGKILL after grace period)")
+	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop before killing it.")
 	if err := cmd.Parse(args); err != nil {
 	if err := cmd.Parse(args); err != nil {
 		return nil
 		return nil
 	}
 	}
@@ -526,7 +526,7 @@ func (cli *DockerCli) CmdStop(args ...string) error {
 
 
 func (cli *DockerCli) CmdRestart(args ...string) error {
 func (cli *DockerCli) CmdRestart(args ...string) error {
 	cmd := cli.Subcmd("restart", "[OPTIONS] CONTAINER [CONTAINER...]", "Restart a running container")
 	cmd := cli.Subcmd("restart", "[OPTIONS] CONTAINER [CONTAINER...]", "Restart a running container")
-	nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Number of seconds to wait for the container to stop. Default=10")
+	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")
 	if err := cmd.Parse(args); err != nil {
 	if err := cmd.Parse(args); err != nil {
 		return nil
 		return nil
 	}
 	}

+ 2 - 2
docs/sources/reference/api/docker_remote_api_v1.9.rst

@@ -432,7 +432,7 @@ Stop a container
 
 
            HTTP/1.1 204 OK
            HTTP/1.1 204 OK
 
 
-        :query t: number of seconds to wait for the container to stop
+        :query t: number of seconds to wait before killing the container
         :statuscode 204: no error
         :statuscode 204: no error
         :statuscode 404: no such container
         :statuscode 404: no such container
         :statuscode 500: server error
         :statuscode 500: server error
@@ -457,7 +457,7 @@ Restart a container
 
 
            HTTP/1.1 204 OK
            HTTP/1.1 204 OK
 
 
-        :query t: number of seconds to wait for the container to stop
+        :query t: number of seconds to wait before killing the container
         :statuscode 204: no error
         :statuscode 204: no error
         :statuscode 404: no such container
         :statuscode 404: no such container
         :statuscode 500: server error
         :statuscode 500: server error

+ 3 - 3
docs/sources/reference/commandline/cli.rst

@@ -1360,11 +1360,11 @@ This example shows 5 containers that might be set up to test a web application c
 
 
     Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
     Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
 
 
-    Stop a running container (Send SIGTERM)
+    Stop a running container (Send SIGTERM, and then SIGKILL after grace period)
 
 
-      -t, --time=10: Number of seconds to wait for the container to stop.
+      -t, --time=10: Number of seconds to wait for the container to stop before killing it.
 
 
-The main process inside the container will receive SIGTERM.
+The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL
 
 
 .. _cli_tag:
 .. _cli_tag:
 
 

+ 3 - 2
integration/server_test.go

@@ -416,7 +416,7 @@ func TestRestartKillWait(t *testing.T) {
 	})
 	})
 }
 }
 
 
-func TestCreateStartRestartKillStartKillRm(t *testing.T) {
+func TestCreateStartRestartStopStartKillRm(t *testing.T) {
 	eng := NewTestEngine(t)
 	eng := NewTestEngine(t)
 	srv := mkServerFromEngine(eng, t)
 	srv := mkServerFromEngine(eng, t)
 	defer mkRuntimeFromEngine(eng, t).Nuke()
 	defer mkRuntimeFromEngine(eng, t).Nuke()
@@ -456,7 +456,8 @@ func TestCreateStartRestartKillStartKillRm(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	job = eng.Job("kill", id)
+	job = eng.Job("stop", id)
+	job.SetenvInt("t", 15)
 	if err := job.Run(); err != nil {
 	if err := job.Run(); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}

+ 10 - 2
runtime/container.go

@@ -903,12 +903,20 @@ func (container *Container) Stop(seconds int) error {
 
 
 	// 1. Send a SIGTERM
 	// 1. Send a SIGTERM
 	if err := container.KillSig(15); err != nil {
 	if err := container.KillSig(15); err != nil {
-		return err
+		utils.Debugf("Error sending kill SIGTERM: %s", err)
+		log.Print("Failed to send SIGTERM to the process, force killing")
+		if err := container.KillSig(9); err != nil {
+			return err
+		}
 	}
 	}
 
 
 	// 2. Wait for the process to exit on its own
 	// 2. Wait for the process to exit on its own
 	if err := container.WaitTimeout(time.Duration(seconds) * time.Second); err != nil {
 	if err := container.WaitTimeout(time.Duration(seconds) * time.Second); err != nil {
-		return err
+		log.Printf("Container %v failed to exit within %d seconds of SIGTERM - using the force", container.ID, seconds)
+		// 3. If it doesn't, then send SIGKILL
+		if err := container.Kill(); err != nil {
+			return err
+		}
 	}
 	}
 	return nil
 	return nil
 }
 }