From c38fadfd2f601aec0250c16c83fb8fa68c073b80 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Aug 2013 16:38:02 -0700 Subject: [PATCH] core: config.vm.graceful_halt_timeout to specify graceful halt timeout --- CHANGELOG.md | 3 +++ config/default.rb | 3 +-- lib/vagrant/action/builtin/graceful_halt.rb | 14 +++++++++----- plugins/kernel_v2/config/vm.rb | 7 +++---- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6b0cc20..f4999c037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ BACKWARDS INCOMPATIBILITY: - `config.ssh.max_tries` is gone. Instead of maximum tries, Vagrant now uses a simple overall timeout value `config.ssh.timeout` to wait for the machine to boot up. + - `config.vm.graceful_halt_retry_*` settings are gone. Instead, a single + timeout is now used to wait for a graceful halt to work, specified + by `config.vm.graceful_halt_timeout`. FEATURES: diff --git a/config/default.rb b/config/default.rb index c5476792d..13d8ea1e8 100644 --- a/config/default.rb +++ b/config/default.rb @@ -13,8 +13,7 @@ Vagrant.configure("2") do |config| config.vm.usable_port_range = (2200..2250) config.vm.box_url = nil config.vm.base_mac = nil - config.vm.graceful_halt_retry_count = 60 - config.vm.graceful_halt_retry_interval = 1 + config.vm.graceful_halt_timeout = 60 # Share SSH locally by default config.vm.network :forwarded_port, diff --git a/lib/vagrant/action/builtin/graceful_halt.rb b/lib/vagrant/action/builtin/graceful_halt.rb index fc218a94c..c119af4e9 100644 --- a/lib/vagrant/action/builtin/graceful_halt.rb +++ b/lib/vagrant/action/builtin/graceful_halt.rb @@ -1,4 +1,5 @@ require "log4r" +require "timeout" module Vagrant module Action @@ -52,11 +53,14 @@ module Vagrant end @logger.debug("Waiting for target graceful halt state: #{@target_state}") - count = 0 - while env[:machine].state.id != @target_state - count += 1 - return if count >= env[:machine].config.vm.graceful_halt_retry_count - sleep env[:machine].config.vm.graceful_halt_retry_interval + begin + Timeout.timeout(env[:machine].config.vm.graceful_halt_timeout) do + while env[:machine].state.id != @target_state + sleep 1 + end + end + rescue Timeout::Error + # Don't worry about it, we catch the case later. end # The result of this matters on whether we reached our diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 5870865a6..019169303 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -18,8 +18,7 @@ module VagrantPlugins attr_accessor :box attr_accessor :box_url attr_accessor :box_download_insecure - attr_accessor :graceful_halt_retry_count - attr_accessor :graceful_halt_retry_interval + attr_accessor :graceful_halt_timeout attr_accessor :guest attr_accessor :hostname attr_accessor :usable_port_range @@ -27,8 +26,7 @@ module VagrantPlugins def initialize @box_download_insecure = UNSET_VALUE - @graceful_halt_retry_count = UNSET_VALUE - @graceful_halt_retry_interval = UNSET_VALUE + @graceful_halt_timeout = UNSET_VALUE @guest = UNSET_VALUE @hostname = UNSET_VALUE @provisioners = [] @@ -247,6 +245,7 @@ module VagrantPlugins def finalize! # Defaults @box_download_insecure = false if @box_download_insecure == UNSET_VALUE + @graceful_halt_timeout = 300 if @graceful_halt_timeout == UNSET_VALUE @guest = nil if @guest == UNSET_VALUE @hostname = nil if @hostname == UNSET_VALUE @hostname = @hostname.to_s if @hostname