Last active
October 21, 2016 15:00
-
-
Save scoates/4b7d2d2458e5043f21ce to your computer and use it in GitHub Desktop.
Ensure one VM ("gateway") is running before allowing the others
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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.
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
Someone tell me why this is a bad idea, and preferably: how to do it via internal APIs. (-: