Class: VagrantPlugins::ProviderZone::Action::Restart

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-zones/action/restart.rb

Overview

This is used to restart the zone

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ Restart

Returns a new instance of Restart.



13
14
15
16
# File 'lib/vagrant-zones/action/restart.rb', line 13

def initialize(app, _env)
  @logger = Log4r::Logger.new('vagrant_zones::action::restart')
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-zones/action/restart.rb', line 18

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