From 9d4ab18f42b542b5dff810eb3900ade61dd0756e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Oct 2014 17:50:45 -0700 Subject: [PATCH] providers/docker: stop_timeout [GH-4504] --- CHANGELOG.md | 5 +++++ plugins/providers/docker/action/stop.rb | 2 +- plugins/providers/docker/config.rb | 8 ++++++++ plugins/providers/docker/driver.rb | 4 ++-- test/unit/plugins/providers/docker/config_test.rb | 1 + website/docs/source/v2/docker/configuration.html.md | 3 +++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e19f3b65..d0d93c0a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 1.7.0 (unreleased) +IMPROVEMENTS: + + - providers/docker: `stop_timeout` can be used to modify the `docker stop` + timeout. [GH-4504] + BUG FIXES: - core: Fix cases where sometimes SSH connection would hang. diff --git a/plugins/providers/docker/action/stop.rb b/plugins/providers/docker/action/stop.rb index f743c8b6c..2a30cf4a3 100644 --- a/plugins/providers/docker/action/stop.rb +++ b/plugins/providers/docker/action/stop.rb @@ -11,7 +11,7 @@ module VagrantPlugins driver = machine.provider.driver if driver.running?(machine.id) env[:ui].info I18n.t("docker_provider.messages.stopping") - driver.stop(machine.id) + driver.stop(machine.id, machine.provider_config.stop_timeout) end @app.call(env) end diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index a0a2421fc..df7a85d2a 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -61,6 +61,12 @@ module VagrantPlugins # @return [Boolean] attr_accessor :remains_running + # The time to wait before sending a SIGTERM to the container + # when it is stopped. + # + # @return [Integer] + attr_accessor :stop_timeout + # The name of the machine in the Vagrantfile set with # "vagrant_vagrantfile" that will be the docker host. Defaults # to "default" @@ -99,6 +105,7 @@ module VagrantPlugins @ports = UNSET_VALUE @privileged = UNSET_VALUE @remains_running = UNSET_VALUE + @stop_timeout = UNSET_VALUE @volumes = [] @vagrant_machine = UNSET_VALUE @vagrant_vagrantfile = UNSET_VALUE @@ -151,6 +158,7 @@ module VagrantPlugins @ports = [] if @ports == UNSET_VALUE @privileged = false if @privileged == UNSET_VALUE @remains_running = true if @remains_running == UNSET_VALUE + @stop_timeout = 1 if @stop_timeout == UNSET_VALUE @vagrant_machine = nil if @vagrant_machine == UNSET_VALUE @vagrant_vagrantfile = nil if @vagrant_vagrantfile == UNSET_VALUE diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index f5d64fe32..b1eec3453 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -95,9 +95,9 @@ module VagrantPlugins end end - def stop(cid) + def stop(cid, timeout) if running?(cid) - execute('docker', 'stop', '-t', '1', cid) + execute('docker', 'stop', '-t', timeout.to_s, cid) end end diff --git a/test/unit/plugins/providers/docker/config_test.rb b/test/unit/plugins/providers/docker/config_test.rb index ac20f6bc3..e1239794c 100644 --- a/test/unit/plugins/providers/docker/config_test.rb +++ b/test/unit/plugins/providers/docker/config_test.rb @@ -47,6 +47,7 @@ describe VagrantPlugins::DockerProvider::Config do its(:image) { should be_nil } its(:name) { should be_nil } its(:privileged) { should be_false } + its(:stop_timeout) { should eq(1) } its(:vagrant_machine) { should be_nil } its(:vagrant_vagrantfile) { should be_nil } end diff --git a/website/docs/source/v2/docker/configuration.html.md b/website/docs/source/v2/docker/configuration.html.md index 9b1583abb..a4d8d760c 100644 --- a/website/docs/source/v2/docker/configuration.html.md +++ b/website/docs/source/v2/docker/configuration.html.md @@ -62,6 +62,9 @@ you may set. A complete reference is shown below. of time. If false, then Vagrant expects that this container will automatically stop at some point, and won't error if it sees it do that. + * `stop_timeout` (integer) - The amount of time to wait when stopping + a container before sending a SIGTERM to the process. + * `vagrant_machine` (string) - The name of the Vagrant machine in the `vagrant_vagrantfile` to use as the host machine. This defaults to "default".