2012-08-04 18:16:31 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
|
|
|
class Halt
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
current_state = env[:machine].provider.state
|
|
|
|
if current_state == :running || current_state == :gurumeditation
|
|
|
|
# If the VM is running and we're not forcing, we can
|
|
|
|
# attempt a graceful shutdown
|
|
|
|
if current_state == :running && !env["force"]
|
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.halt.graceful")
|
2012-08-13 01:35:19 +00:00
|
|
|
env[:machine].guest.halt
|
2012-08-04 18:16:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# If we're not powered off now, then force it
|
2012-08-13 01:54:52 +00:00
|
|
|
if env[:machine].provider.state != :poweroff
|
2012-08-04 18:16:31 +00:00
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.halt.force")
|
2012-08-13 01:54:52 +00:00
|
|
|
env[:machine].provider.halt
|
2012-08-04 18:16:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Sleep for a second to verify that the VM properly
|
|
|
|
# cleans itself up
|
|
|
|
sleep 1 if !env["vagrant.test"]
|
|
|
|
end
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|