diff --git a/plugins/providers/docker/action/host_machine.rb b/plugins/providers/docker/action/host_machine.rb index e31377552..ddcaae216 100644 --- a/plugins/providers/docker/action/host_machine.rb +++ b/plugins/providers/docker/action/host_machine.rb @@ -1,3 +1,5 @@ +require "digest/md5" + require "log4r" require "vagrant/util/platform" @@ -24,15 +26,30 @@ module VagrantPlugins env[:machine].ui.output(I18n.t( "docker_provider.host_machine_needed")) - # TODO(mitchellh): process-level lock so that we don't - # step on parallel Vagrant's toes. - host_machine = env[:machine].provider.host_vm + # Grab a process-level lock on the data directory of this VM + # so that we only try to spin up one at a time + hash = Digest::MD5.hexdigest(host_machine.data_dir.to_s) + begin + env[:machine].env.lock(hash) do + setup_host_machine(host_machine, env) + end + rescue Vagrant::Errors::EnvironmentLockedError + sleep 1 + retry + end + + @app.call(env) + end + + protected + + def setup_host_machine(host_machine, env) # See if the machine is ready already. if host_machine.communicate.ready? env[:machine].ui.detail(I18n.t("docker_provider.host_machine_ready")) - return @app.call(env) + return end # Create a UI for this machine that stays at the detail level @@ -47,8 +64,6 @@ module VagrantPlugins host_machine.with_ui(proxy_ui) do host_machine.action(:up) end - - @app.call(env) end end end diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 925ca03d8..219a5fc05 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -528,9 +528,9 @@ module VagrantPlugins "--name", name, "--transient") - execute( - "setextradata", @uuid, - "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") + execute( + "setextradata", @uuid, + "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") rescue Vagrant::Errors::VBoxManageError => e if e.extra_data[:stderr].include?("VBOX_E_FILE_ERROR") # The folder doesn't exist. ignore.