mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ensure shutdown timeout adjusted if graceful halt fails
This commit is contained in:
@@ -139,18 +139,22 @@ module VagrantPlugins
|
||||
b3.use ResumeDomain if env2[:result]
|
||||
end
|
||||
|
||||
# only perform shutdown if VM is running
|
||||
b2.use Call, IsRunning do |env2, b3|
|
||||
next unless env2[:result]
|
||||
|
||||
# VM is running, halt it.
|
||||
b3.use Call, GracefulHalt, :shutoff, :running do |env3, b4|
|
||||
if !env3[:result]
|
||||
b4.use Call, ShutdownDomain, :shutoff, :running do |env4, b5|
|
||||
if !env4[:result]
|
||||
b5.use HaltDomain
|
||||
end
|
||||
end
|
||||
end
|
||||
b3.use Call, Message, "Attempting nice shutdowns..." do |_, b4|
|
||||
# ShutdownDomain will perform the domain shutdown on the out calls
|
||||
# so it runs after the remaining actions in the same action builder.
|
||||
b4.use ShutdownDomain, :shutoff, :running
|
||||
b4.use GracefulHalt, :shutoff, :running
|
||||
end
|
||||
|
||||
# Only force halt if previous actions insufficient.
|
||||
b3.use Call, IsRunning do |env3, b4|
|
||||
next unless env3[:result]
|
||||
|
||||
b4.use HaltDomain
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,26 @@ module VagrantPlugins
|
||||
|
||||
def call(env)
|
||||
timeout = env[:machine].config.vm.graceful_halt_timeout
|
||||
|
||||
start_time = Time.now
|
||||
|
||||
# call nested action first under the assumption it should try to
|
||||
# handle shutdown via client capabilities
|
||||
@app.call(env)
|
||||
|
||||
# return if successful, otherwise will ensure result is set to false
|
||||
env[:result] = env[:machine].state.id == @target_state
|
||||
|
||||
return if env[:result]
|
||||
|
||||
current_time = Time.now
|
||||
|
||||
# if we've already exceeded the timeout
|
||||
return if current_time - start_time >= timeout
|
||||
|
||||
# otherwise construct a new timeout.
|
||||
timeout = timeout - (current_time - start_time)
|
||||
|
||||
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
||||
if env[:machine].state.id == @source_state
|
||||
env[:ui].info(I18n.t('vagrant_libvirt.shutdown_domain'))
|
||||
@@ -22,8 +42,6 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
env[:result] = env[:machine].state.id == @target_state
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user