Make use of the new WaitForCommunicator action on boot
This commit is contained in:
parent
1da7b60cd8
commit
791a93fe9e
2 changed files with 6 additions and 32 deletions
|
@ -19,6 +19,11 @@ require 'vagrant-lxc/action/remove_temporary_files'
|
||||||
require 'vagrant-lxc/action/setup_package_files'
|
require 'vagrant-lxc/action/setup_package_files'
|
||||||
require 'vagrant-lxc/action/share_folders'
|
require 'vagrant-lxc/action/share_folders'
|
||||||
|
|
||||||
|
unless Vagrant::LXC.vagrant_1_3_or_later
|
||||||
|
require 'vagrant-lxc/action/wait_for_communicator'
|
||||||
|
Vagrant::Action::Builtin.const_set :WaitForCommunicator, Vagrant::LXC::Action::WaitForCommunicator
|
||||||
|
end
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module LXC
|
module LXC
|
||||||
module Action
|
module Action
|
||||||
|
@ -51,6 +56,7 @@ module Vagrant
|
||||||
b.use Vagrant::Action::Builtin::SetHostname
|
b.use Vagrant::Action::Builtin::SetHostname
|
||||||
b.use ForwardPorts
|
b.use ForwardPorts
|
||||||
b.use Boot
|
b.use Boot
|
||||||
|
b.use Vagrant::Action::Builtin::WaitForCommunicator, [:starting, :running]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,41 +15,9 @@ module Vagrant
|
||||||
|
|
||||||
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
env[:ui].info I18n.t("vagrant_lxc.messages.starting")
|
||||||
env[:machine].provider.driver.start(config.customizations)
|
env[:machine].provider.driver.start(config.customizations)
|
||||||
raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
|
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stolen from on VagrantPlugins::ProviderVirtualBox::Action::Boot
|
|
||||||
def wait_for_boot
|
|
||||||
@env[:ui].info I18n.t("vagrant_lxc.messages.waiting_for_start")
|
|
||||||
|
|
||||||
@env[:machine].config.ssh.max_tries.to_i.times do |i|
|
|
||||||
if @env[:machine].communicate.ready?
|
|
||||||
@env[:ui].info I18n.t("vagrant_lxc.messages.container_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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue