Use the new GracefulHalt built-in for VirtualBox
This commit is contained in:
parent
51540496a9
commit
31448c4cd4
|
@ -23,8 +23,8 @@ module VagrantPlugins
|
|||
autoload :DestroyUnusedNetworkInterfaces, File.expand_path("../action/destroy_unused_network_interfaces", __FILE__)
|
||||
autoload :DiscardState, File.expand_path("../action/discard_state", __FILE__)
|
||||
autoload :Export, File.expand_path("../action/export", __FILE__)
|
||||
autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__)
|
||||
autoload :ForwardPorts, File.expand_path("../action/forward_ports", __FILE__)
|
||||
autoload :Halt, File.expand_path("../action/halt", __FILE__)
|
||||
autoload :HostName, File.expand_path("../action/host_name", __FILE__)
|
||||
autoload :Import, File.expand_path("../action/import", __FILE__)
|
||||
autoload :IsRunning, File.expand_path("../action/is_running", __FILE__)
|
||||
|
@ -110,7 +110,11 @@ module VagrantPlugins
|
|||
if env[:result]
|
||||
b2.use CheckAccessible
|
||||
b2.use DiscardState
|
||||
b2.use Halt
|
||||
b2.use Call, GracefulHalt, :poweroff, :running do |env2, b3|
|
||||
if !env[:result]
|
||||
b3.use ForcedHalt
|
||||
end
|
||||
end
|
||||
else
|
||||
b2.use MessageNotCreated
|
||||
end
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class ForcedHalt
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
current_state = env[:machine].state.id
|
||||
if current_state == :running || current_state == :gurumeditation
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
||||
env[:machine].provider.driver.halt
|
||||
end
|
||||
|
||||
# Sleep for a second to verify that the VM properly
|
||||
# cleans itself up. Silly VirtualBox.
|
||||
sleep 1 if !env["vagrant.test"]
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class Halt
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
current_state = env[:machine].provider.state.id
|
||||
if current_state == :running || current_state == :gurumeditation
|
||||
# If the VM is running and we're not forcing, we can
|
||||
# attempt a graceful shutdown
|
||||
if current_state == :running && !env[:force]
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.halt.graceful")
|
||||
env[:machine].guest.halt
|
||||
end
|
||||
|
||||
# If we're not powered off now, then force it
|
||||
if env[:machine].provider.state.id != :poweroff
|
||||
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
||||
env[:machine].provider.driver.halt
|
||||
end
|
||||
|
||||
# Sleep for a second to verify that the VM properly
|
||||
# cleans itself up
|
||||
sleep 1 if !env["vagrant.test"]
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue