From d8d5a66fa587a93d1a7b2e0430237176193386c7 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 9 Jul 2015 12:34:04 -0600 Subject: [PATCH 1/3] Add a function to get to the "original" environment with Vagrant This function only works when used with the official Vagrant installer. --- lib/vagrant.rb | 16 ++++++++++++++++ test/unit/vagrant_test.rb | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index eba026c51..3ae4c1154 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -227,6 +227,22 @@ module Vagrant requirements: requirements.join(", "), version: VERSION end + + # This allows plugin developers to access the original environment before + # Vagrant even ran. This is useful when shelling out, especially to other + # Ruby processes. + # + # @return [Hash] + def self.original_env + {}.tap do |h| + ENV.each do |k,v| + if k.start_with?("VAGRANT_OLD_ENV") + key = k.sub(/^VAGRANT_OLD_ENV_/, "") + h[key] = v + end + end + end + end end # Default I18n to load the en locale diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index ec317a628..06f7489ca 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -98,4 +98,23 @@ describe Vagrant do to raise_error(Vagrant::Errors::VagrantVersionBad) end end + + describe "original_env" do + before do + ENV["VAGRANT_OLD_ENV_foo"] = "test" + ENV["VAGRANT_OLD_ENV_bar"] = "test" + end + + after do + ENV["VAGRANT_OLD_ENV_foo"] = "test" + ENV["VAGRANT_OLD_ENV_bar"] = "test" + end + + it "should return the original environment" do + expect(Vagrant.original_env).to eq( + "foo" => "test", + "bar" => "test", + ) + end + end end From 3ba10b43abda41a433356b496757abe64f6c31cb Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 9 Jul 2015 12:36:57 -0600 Subject: [PATCH 2/3] Restore the original environment from Bundler and the installer if given --- lib/vagrant/util/subprocess.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/vagrant/util/subprocess.rb b/lib/vagrant/util/subprocess.rb index e249b72c1..e610151d2 100644 --- a/lib/vagrant/util/subprocess.rb +++ b/lib/vagrant/util/subprocess.rb @@ -91,6 +91,15 @@ module Vagrant end end + # Reset the Bundler environment back - this is required for anyone who + # is not using the official Vagrant installers and is running Vagrant + # via bundler + if defined?(Bundler::ORIGINAL_ENV) + Bundler::ORIGINAL_ENV.each do |k, v| + process.environment[k] = v + end + end + # Set the environment on the process if we must if @options[:env] @options[:env].each do |k, v| From e46ef7d2f8c7335544a685bbb01986e5fa87f1dc Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 9 Jul 2015 12:37:04 -0600 Subject: [PATCH 3/3] Document debugging the launcher --- .../source/v2/other/environmental-variables.html.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/website/docs/source/v2/other/environmental-variables.html.md b/website/docs/source/v2/other/environmental-variables.html.md index c7099a6b7..b42e6774d 100644 --- a/website/docs/source/v2/other/environmental-variables.html.md +++ b/website/docs/source/v2/other/environmental-variables.html.md @@ -9,7 +9,15 @@ Vagrant has a set of environmental variables that can be used to configure and control it in a global way. This page lists those environmental variables. -## VAGRANT\_CHECKPOINT\_DISABLE +## VAGRANT\_DEBUG\_LAUNCHER + +For performance reasons, especially for Windows users, Vagrant uses a static +binary to launch the actual Vagrant process. If you have _very_ early issues +when launching Vagrant from the official installer, you can specify the +`VAGRANT_DEBUG_LAUNCHER` environment variable to output debugging information +about the launch process. + +## VAGRANT\_CHECKPOINT\_DISABLE Vagrant does occasional network calls to check whether the version of Vagrant that is running locally is up to date. We understand that software making remote