Skip to content

Instantly share code, notes, and snippets.

@scoates
Last active October 21, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scoates/4b7d2d2458e5043f21ce to your computer and use it in GitHub Desktop.
Save scoates/4b7d2d2458e5043f21ce to your computer and use it in GitHub Desktop.
Ensure one VM ("gateway") is running before allowing the others
# Check to see that we have a gateway running before we allow the `up` of another VM
# This is a filthy hack
if ARGV[0] != 'up'
GATEWAY_STATUS = 'running' # this is irrelevant for everything but `vagrant up`
# if we don't do this, we could fork forever in the else block, here
else
GATEWAY_STATUS = `vagrant status --machine-readable | grep 'gateway,state,' | awk -F, {'print $4'}`.strip!
if GATEWAY_STATUS != 'running'
puts "*** The gateway is not running. You can not 'up' any other VMs."
end
end
Vagrant.configure(2) do |config|
if GATEWAY_STATUS == 'running'
config.vm.define :othervm, primary: false, autostart: false do |config|
bootstrap config.vm # custom
end
end
if GATEWAY_STATUS == 'running'
config.vm.define :yetanothervm, primary: false, autostart: false do |config|
bootstrap config.vm # custom
end
end
config.vm.define :gateway, primary: true, autostart: true do |config|
bootstrap config.vm # custom
end
end
@scoates
Copy link
Author

scoates commented Oct 29, 2015

Someone tell me why this is a bad idea, and preferably: how to do it via internal APIs. (-:

@nicksloan
Copy link

Does it matter if the gateway is up? What you really care about is connectivity over your VPN.Though I suppose the conditional is the really ugly part.

@scoates
Copy link
Author

scoates commented Oct 21, 2016

Ha. Just noticed your comment @nicksloan. It does matter because we run apt-cacher-ng on the gateway, so other nodes "need" it to be running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment