I am trying to use guard's --listen-on
option with vagrant as outlined here, but I am unable to get it to work.
If I add config.vm.network :forwarded_port, guest: 4000, host: 4000
to my Vagrantfile
and subsequently try to start listen with listen -f 127.0.0.1:4000
, I get an error: Broadcaster.initialize: Address already in use - bind(2) for "127.0.0.1" port 4000
.
If I try to start listen and then start vagrant, vagrant complains similarly:
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 4000 is already in use on the host machine.
So I tried some other things while omitting the port 4000 forwarding in the Vagrantfile
:
If I omit the port 4000 forwarding in my Vagrantfile
, then I can successfully start listen with listen -f 127.0.0.1:4000
. But then when I run guard -o "10.0.2.2:4000" -w "/home/me/my_project/"
in my vagrant guest, guard does not do anything when a file changes. Adding a -v
flag to the listen
call reveals that changes are being picked up correctly on the host.
I also tried listen -f 10.11.12.1:4000
on the host combined with guard -o "10.11.12.1:4000" -w "/home/me/my_project/"
on the guest with the same results of guard not do anything when a file changes.
Combining listen -f 127.0.0.1:4000
with guard -o "10.11.12.1:4000" -w "/home/me/my_project/"
results in guard being unable to connect.
I've also tried port forwarding with ssh:
listen -vf 127.0.0.1:4000 # host
ssh -R 4000:localhost:4000 [email protected] # connect
guard -o "127.0.0.1:4000" -w "/home/me/my_project" # guest
Everything seems to go okay with port forwarding, but again guard never does anything when files are changed.
Both the host and guest are ubuntu 14.04.
The network config in my Vagrantfile
is as follows:
config.vm.network 'forwarded_port', guest: 80, host: 3000
config.vm.network 'private_network', ip: '10.11.12.13'
What is the proper way to make this work?