Update serve mode setup to prevent environment loading

This commit is contained in:
Chris Roberts 2021-08-13 13:49:15 -07:00 committed by Paul Hinze
parent 96ac78a9a4
commit e56b2df70d
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -194,21 +194,20 @@ begin
end
}.new(argv.dup, nil).sub_command
# Check if we are running the server
# Check if we are running the server. If we are, we extract
# the command from the plugin manager and run it directly.
# Doing this prevents Vagrant from attempting to load an
# Environment directly.
if sub_cmd == "serve"
Vagrant.enable_server_mode!
# NOTE: We stub the client option to allow the environment to
# be initialized for startup since it will raise an
# exception if it is unset. We don't care about the
# initially created environment, we just need it long
# enough for our serve command to get executed.
opts[:client] = :stub
end
cmd = Vagrant.plugin("2").manager.commands[:serve].first.call
result = cmd.new([], nil).execute
exit(result)
else
# Create the environment, which is the cwd of wherever the
# `vagrant` command was invoked from
logger.debug("Creating Vagrant environment")
env = Vagrant::Environment.new(opts)
env = klass.new(opts)
# If we are running with the Windows Subsystem for Linux do
# some extra setup to allow access to Vagrant managed machines
@ -253,6 +252,7 @@ begin
# Exit with the exit status from our CLI command
exit(exit_status)
end
rescue Exception => e
# It is possible for errors to happen in Vagrant's initialization. In
# this case, we don't have access to this class yet, so we check for it.