Sha256: 29e51eea92eca67a437687c2b682f46f09f81c78202d6e14a08a96510d2d3a86

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require 'vagrant/util/guest_inspection'
require "log4r"

module VagrantPlugins
  module GuestLinux
    module Cap
      class Reboot
        extend Vagrant::Util::GuestInspection::Linux
        MAX_REBOOT_RETRY_DURATION = 120

        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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/guests/linux/cap/reboot.rb
vagrant-unbundled-2.2.10.0 plugins/guests/linux/cap/reboot.rb
vagrant-unbundled-2.2.9.0 plugins/guests/linux/cap/reboot.rb
vagrant-unbundled-2.2.8.0 plugins/guests/linux/cap/reboot.rb