From e8459de8cb217707ef5b93eaf6393be5043199a0 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 3 Mar 2013 01:19:20 -0300 Subject: [PATCH] Retry after create script execution and increase sleep time when trying to get container ip Dont know why but I started getting a lot of timeouts so lets make the container scripts wait a bit more before failing. --- example/Gemfile | 5 ----- lib/vagrant-lxc/container.rb | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/example/Gemfile b/example/Gemfile index 6130da0..0adc426 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -1,8 +1,3 @@ -unless ENV['USER'] == 'vagrant' - puts 'This Gemfile is meant to be used from the dev box' - exit 1 -end - source "https://rubygems.org" gem 'vagrant-lxc', path: '../' diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index 4ae4386..b3daea1 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -54,13 +54,16 @@ module Vagrant private_key = Vagrant.source_root.join('keys', 'vagrant').expand_path.to_s @logger.debug 'Running after-create-script from box metadata' - cmd = [ - script, - '-r', "#{CONTAINERS_PATH}/#{@name}/rootfs", - '-k', private_key, - '-i', dhcp_ip - ] - execute *cmd + + # TODO: Gotta write somewhere that it has to be indempotent + retryable(:tries => 5, :sleep => 1.5) do + execute *[ + script, + '-r', "#{CONTAINERS_PATH}/#{@name}/rootfs", + '-k', private_key, + '-i', dhcp_ip + ] + end end def start @@ -101,7 +104,7 @@ module Vagrant ip = '' # Right after creation lxc reports the container as running # before DNS is returning the right IP, so have to wait for a while - retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 1) do + retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do # By default LXC supplies a dns server on 10.0.3.1 so we request the IP # of our target from there. # Tks to: https://github.com/neerolyte/vagueant/blob/master/bin/vagueant#L340