Class: VagrantWindows::Guest::Cap::Halt

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-windows/guest/cap/halt.rb

Class Method Summary collapse

Class Method Details

.halt(machine) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vagrant-windows/guest/cap/halt.rb', line 5

def self.halt(machine)
  machine.communicate.execute("shutdown /s /t 1 /c \"Vagrant Halt\" /f /d p:4:1")

  # Wait until the VM's state is actually powered off. If this doesn't
  # occur within a reasonable amount of time (15 seconds by default),
  # then simply return and allow Vagrant to kill the machine.
  count = 0
  while machine.state != :poweroff
    count += 1

    return if count >= machine.config.windows.halt_timeout
    sleep machine.config.windows.halt_check_interval
  end
end