Sha256: 4a6266be2f3be06d2254298964c99ff3892bd2028b3029d596e8dbfd3ad8aaa9

Contents?: true

Size: 1.62 KB

Versions: 54

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require 'log4r'
require 'vagrant-zones/util/timer'
require 'vagrant/util/retryable'

module VagrantPlugins
  module ProviderZone
    module Action
      # This is used to restart the zone
      class Restart
        include Vagrant::Util::Retryable
        def initialize(app, _env)
          @logger = Log4r::Logger.new('vagrant_zones::action::restart')
          @app = app
        end

        def call(env)
          @machine = env[:machine]
          @driver = @machine.provider.driver
          ui = env[:ui]
          ui.info(I18n.t('vagrant_zones.graceful_restart'))
          @driver.control(ui, 'restart')

          env[:metrics] ||= {}
          env[:metrics]['instance_ssh_time'] = Util::Timer.time do
            retryable(on: Errors::TimeoutError, tries: 300) do
              # If we're interrupted don't worry about waiting
              next if env[:interrupted]

              loop do
                break if env[:interrupted]
                break unless env[:machine].communicate.ready?
              end
            end
          end

          ui.info(I18n.t('vagrant_zones.zone_gracefully_stopped_waiting_for_boot'))
          env[:metrics] ||= {}
          env[:metrics]['instance_ssh_time'] = Util::Timer.time do
            retryable(on: Errors::TimeoutError, tries: 300) do
              # If we're interrupted don't worry about waiting
              next if env[:interrupted]
              break if env[:machine].communicate.ready?
            end
          end
          ui.info(I18n.t('vagrant_zones.zone_gracefully_restarted'))
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
vagrant-zones-0.1.98 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.97 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.96 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.94 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.93 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.92 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.91 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.90 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.89 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.88 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.87 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.86 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.85 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.84 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.83 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.82 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.81 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.80 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.79 lib/vagrant-zones/action/restart.rb
vagrant-zones-0.1.78 lib/vagrant-zones/action/restart.rb