attempt to autocorrect port mapping if it occurs on up - defaults to true in servers.yaml - doesn't appear to be too reliable, currently fails for me and throws the following warning before attempting to install, rather than fail silently with the locally bound port overriding the forwarded brooklyn port: ``` ==> brooklyn: Clearing any previously set forwarded ports... Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 8081 is already in use on the host machine.
To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port: config.vm.network :forwarded_port, guest: 80, host: 1234 Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. ``` - Updated the Vagrantfile to point the user at `servers.yaml` when they search for the suggested line in the warning above. Project: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/commit/f08bddf2 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/tree/f08bddf2 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-dist/diff/f08bddf2 Branch: refs/heads/0.9.0 Commit: f08bddf201ab02a4f7066bfa3bcacf01bb430b99 Parents: 4e2ebfd Author: John McCabe <j...@johnmccabe.net> Authored: Wed Apr 6 19:16:25 2016 +0100 Committer: Aled Sage <aled.s...@gmail.com> Committed: Wed Apr 6 20:37:57 2016 +0100 ---------------------------------------------------------------------- vagrant/src/main/vagrant/Vagrantfile | 28 +++++++++++++++++++++++++--- vagrant/src/main/vagrant/servers.yaml | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/f08bddf2/vagrant/src/main/vagrant/Vagrantfile ---------------------------------------------------------------------- diff --git a/vagrant/src/main/vagrant/Vagrantfile b/vagrant/src/main/vagrant/Vagrantfile index fb35a15..9ac586f 100644 --- a/vagrant/src/main/vagrant/Vagrantfile +++ b/vagrant/src/main/vagrant/Vagrantfile @@ -26,6 +26,9 @@ VAGRANTFILE_API_VERSION = "2" # Update OS (Debian/RedHat based only) UPDATE_OS_CMD = "(sudo apt-get update && sudo apt-get -y upgrade) || (sudo yum -y update)" +# Autocorrect Port Clashes +DEFAULT_AUTOCORRECT = false + # Require YAML module require 'yaml' @@ -48,8 +51,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end if server.has_key?("forwarded_ports") - server["forwarded_ports"].each do |ports| - server_config.vm.network "forwarded_port", guest: ports["guest"], host: ports["host"], guest_ip: ports["guest_ip"] + server["forwarded_ports"].each do |port| + if port.has_key?("autocorrect") + autocorrect = true + else + autocorrect = DEFAULT_AUTOCORRECT + end + server_config.vm.network "forwarded_port", guest: port["guest"], host: port["host"], guest_ip: port["guest_ip"], autocorrect: autocorrect end end @@ -73,4 +81,18 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| server_config.vm.post_up_message = server["post_up_message"] end end -end \ No newline at end of file +end + +# ALTERING PORT FORWARDING +# If you are reading this you have likely been instructed by Vagrant to alter the example +# line below due to the forwarded port colliding with one alread in use on your system. +# +# config.vm.network :forwarded_port, guest: 80, host: 1234 +# +# This Vagrantfile does not define the port mapping here, instead you should alter +# the following line in the `servers.yaml` file in this directory. +# +# host: 8081 +# +# Change 8081 to a port that is not in use on your local machine before attempting +# to run vagrant up again. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/brooklyn-dist/blob/f08bddf2/vagrant/src/main/vagrant/servers.yaml ---------------------------------------------------------------------- diff --git a/vagrant/src/main/vagrant/servers.yaml b/vagrant/src/main/vagrant/servers.yaml index 2160782..46a7826 100644 --- a/vagrant/src/main/vagrant/servers.yaml +++ b/vagrant/src/main/vagrant/servers.yaml @@ -44,6 +44,7 @@ servers: forwarded_ports: - guest: 8081 host: 8081 + autocorrect: true shell: env: BROOKLYN_VERSION: 0.9.0