mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Merge pull request #1236 from h0st/halt_domain_fixes
Fix interaction with reload plugin. The existing hardcoded timeout doesn't allow for VMs that take longer to shutdown for a reboot, thus breaking the reload plugin for them. This switches to retrieve the value for graceful shutdown timeout that can be set by Vagrantfile authors to facilitate. Original PR: #1038
This commit is contained in:
@@ -13,22 +13,30 @@ module VagrantPlugins
|
||||
def call(env)
|
||||
env[:ui].info(I18n.t('vagrant_libvirt.halt_domain'))
|
||||
|
||||
timeout = env[:machine].config.vm.graceful_halt_timeout
|
||||
domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
||||
raise Errors::NoDomainError if domain.nil?
|
||||
|
||||
begin
|
||||
env[:machine].guest.capability(:halt)
|
||||
rescue
|
||||
@logger.info('Trying Libvirt graceful shutdown.')
|
||||
domain.shutdown
|
||||
end
|
||||
Timeout.timeout(timeout) do
|
||||
begin
|
||||
env[:machine].guest.capability(:halt)
|
||||
rescue Timeout::Error
|
||||
raise
|
||||
rescue
|
||||
@logger.info('Trying Libvirt graceful shutdown.')
|
||||
# Read domain object again
|
||||
dom = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s)
|
||||
if dom.state.to_s == 'running'
|
||||
dom.shutdown
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
domain.wait_for(30) do
|
||||
!ready?
|
||||
domain.wait_for(timeout) do
|
||||
!ready?
|
||||
end
|
||||
end
|
||||
rescue Fog::Errors::TimeoutError
|
||||
rescue Timeout::Error
|
||||
@logger.info('VM is still running. Calling force poweroff.')
|
||||
domain.poweroff
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user