2013-03-03 05:24:05 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
module Action
|
|
|
|
class Boot < BaseAction
|
|
|
|
def call(env)
|
2013-03-11 03:12:01 +00:00
|
|
|
@env = env
|
|
|
|
|
2013-03-03 07:37:07 +00:00
|
|
|
config = env[:machine].provider_config
|
2013-03-04 04:09:12 +00:00
|
|
|
|
|
|
|
# Allows this middleware to be called multiple times. We need to
|
|
|
|
# support this as base boxes might have after create scripts which
|
|
|
|
# require SSH access
|
|
|
|
unless env[:machine].state.running?
|
2013-03-11 03:12:01 +00:00
|
|
|
env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
|
2013-03-04 04:09:12 +00:00
|
|
|
env[:machine].provider.container.start(config)
|
2013-03-11 03:12:01 +00:00
|
|
|
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
|
2013-03-04 04:09:12 +00:00
|
|
|
end
|
|
|
|
|
2013-03-03 05:24:05 +00:00
|
|
|
@app.call env
|
|
|
|
end
|
2013-03-11 03:12:01 +00:00
|
|
|
|
|
|
|
# Stolen from on VagrantPlugins::ProviderVirtualBox::Action::Boot
|
|
|
|
def wait_for_boot
|
|
|
|
@env[:ui].info I18n.t("vagrant.actions.vm.boot.waiting")
|
|
|
|
|
|
|
|
@env[:machine].config.ssh.max_tries.to_i.times do |i|
|
|
|
|
if @env[:machine].communicate.ready?
|
|
|
|
@env[:ui].info I18n.t("vagrant.actions.vm.boot.ready")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return true so that the vm_failed_to_boot error doesn't
|
|
|
|
# get shown
|
|
|
|
return true if @env[:interrupted]
|
|
|
|
|
|
|
|
# TODO: Find out if there is a command to check if the machine is
|
|
|
|
# starting, `lxc-monitor` shows this information, but I've
|
|
|
|
# never seen it on `lxc-info` which is what it is being used
|
|
|
|
# to determine container status
|
|
|
|
|
|
|
|
# If the VM is not starting or running, something went wrong
|
|
|
|
# and we need to show a useful error.
|
|
|
|
state = @env[:machine].provider.state.id
|
|
|
|
raise Vagrant::Errors::VMFailedToRun if state != :starting && state != :running
|
|
|
|
|
|
|
|
sleep 2 if !@env["vagrant.test"]
|
|
|
|
end
|
|
|
|
|
|
|
|
@env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
|
|
|
|
false
|
|
|
|
end
|
2013-03-03 05:24:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|