Previously the maximum amount of time Vagrant would poll for whether a machine has successfully reboot was hard coded to 120 seconds. This change introduces the VAGRANT_MAX_REBOOT_RETRY_TIMEOUT environment variable to allow this attribute to be configurable. Add RSpec tests of the maximum retry logic. Since the maximum retries are configured as a constant, we'd need to reload the class and that's fairly ugly to do in RSpec. Fixes #11695
49 lines
1.3 KiB
Ruby
49 lines
1.3 KiB
Ruby
require 'vagrant/util/guest_inspection'
|
|
require "log4r"
|
|
|
|
module VagrantPlugins
|
|
module GuestLinux
|
|
module Cap
|
|
class Reboot
|
|
extend Vagrant::Util::GuestInspection::Linux
|
|
MAX_REBOOT_RETRY_DURATION = ENV.fetch('VAGRANT_MAX_REBOOT_RETRY_TIMEOUT', 120).to_i
|
|
|
|
def self.reboot(machine)
|
|
@logger = Log4r::Logger.new("vagrant::linux::reboot")
|
|
if systemd?(machine.communicate)
|
|
reboot_script = "systemctl reboot"
|
|
else
|
|
reboot_script = "reboot"
|
|
end
|
|
|
|
comm = machine.communicate
|
|
|
|
@logger.debug("Issuing reboot command for guest")
|
|
comm.sudo(reboot_script)
|
|
|
|
machine.ui.info(I18n.t("vagrant.guests.capabilities.rebooting"))
|
|
|
|
@logger.debug("Waiting for machine to finish rebooting")
|
|
|
|
wait_remaining = MAX_REBOOT_RETRY_DURATION
|
|
begin
|
|
wait_for_reboot(machine)
|
|
rescue Vagrant::Errors::MachineGuestNotReady => e
|
|
raise if wait_remaining < 0
|
|
@logger.warn("Machine not ready, cannot start reboot yet. Trying again")
|
|
sleep(5)
|
|
wait_remaining -= 5
|
|
retry
|
|
end
|
|
end
|
|
|
|
def self.wait_for_reboot(machine)
|
|
while !machine.guest.ready?
|
|
sleep 10
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|