Guard - enters with a tramp

I am trying to use the guard --listen-on option with a --listen-on , as described here , but I cannot get it to work.

If I add config.vm.network :forwarded_port, guest: 4000, host: 4000 to my Vagrantfile and try to start listening with listen -f 127.0.0.1:4000 , I get the error message: Broadcaster.initialize: Address already in use - bind(2) for "127.0.0.1" port 4000 .

If I try to start listening and then start wandering, the tramp complains in a similar way:

Vagrant cannot redirect the specified ports to this virtual machine because they will encounter another application that is already listening on these ports. Forwarded port up to 4000 is already in use on the host machine.

So, I tried other things without sending port forwarding 4000 to Vagrantfile :

If I omit port forwarding 4000 in my Vagrantfile , then I can successfully start listening 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/" on my stray guest, the guard does nothing when the file changes. Adding the -v flag to the listen call indicates that the changes are correctly accepted on the host.

I also tried listen -f 10.11.12.1:4000 on listen -f 10.11.12.1:4000 on the host in combination with guard -o "10.11.12.1:4000" -w "/home/me/my_project/" on the guest system with the same security results that do nothing when changing the file.

Combining listen -f 127.0.0.1:4000 with guard -o "10.11.12.1:4000" -w "/home/me/my_project/" causes the protector to fail to connect.

I also tried port forwarding using ssh:

 listen -vf 127.0.0.1:4000 # host ssh -R 4000:localhost:4000 vagrant@10.11.12.13 # connect guard -o "127.0.0.1:4000" -w "/home/me/my_project" # guest 

It seems that everything is ok with port forwarding, but again protection never does anything when files are changed.

Both host and guest are ubuntu 14.04.

The network configuration in my Vagrantfile as follows:

 config.vm.network 'forwarded_port', guest: 80, host: 3000 config.vm.network 'private_network', ip: '10.11.12.13' 

What is the right way to make this work?

+6
source share
4 answers

UPDATE 2:

Listen 3.x no longer includes TCP features (see https://github.com/guard/listen/issues/258 ), so you need to block up to 2.x, for example in the Gemfile :

 gem 'listen', '~> 2.9' 

Then follow the instructions below:

UPDATE 1:

For guard > = v2.7.0 to work, you need to listen > = v2.9.0 and magic -r (since the full paths do not match the host and guest):

 listen -r -f 10.11.12.1:4000 # on the host (note "-r" option) guard -o 10.11.12.1:4000 # on the guest (paths relative, so no prob) 

Notes:

  • since guard v2.7.0, -w is only for listening to multiple directories. Instead, start listening in the directory you are looking at.

  • I would only consider Vargrant / ssh forwarding only if you are behind a firewall or you cannot use these ports for any reason - use the virtual IP addresses and network assigned by VM instead (for example, 10.11. 12.1)

  • to debug things in guard , check out: https://github.com/guard/guard/wiki/Understanding-Guard (worth a look)

  • starting the TCP listening server at 127.0.0.1 does not make sense (if, for example, you should not use the complex ssh port forwarding setting)

+5
source

See the Cezary Baginski answer for a more concise answer and how to make this work a newer (> = 2.7.0) version of the guard. I am going to leave this answer for context.


Armed with Cesari Baginski's advice on how networks should work and are still unable to get this setup to work, I continued to research further with the assumption that something was supposed to break between Jamie Lawrence / blog implementation and now.

Therefore, I decided to downgrade guard and listen to versions released around the same time period (February 24, 2014). This gave me:

 gem 'guard', '2.5.1' gem 'listen', '2.6.1' 

After that, I encountered an error that I decided to solve by lowering guard-rspec to version in about the same time period:

 gem 'guard-rspec', '4.2.8' 

I was still getting a (different) error, so I restored the new Guard file with guard init rspec . Note that prior to this, protection worked fine on the host and worked with the guest as polling or rsync (although polling performance / rsync was terrible) - Guardfile was not a problem.

So, after this the moment of truth has come:

 listen -f 10.11.12.1:4000 # on the host guard -o 10.11.12.1:4000 -w "/home/me/my_project" # on the guest 

Finally, I got it to work.

Then I went through guard releases from 2.5.1 to 2.12.4 in binary search mode to try to determine where something had broken. I found that this just stops working in guard > 2.6.1 .

 # works gem 'guard', '2.6.1' gem 'listen', '2.8.6' gem 'guard-rspec', '4.2.8' # does not work gem 'guard', '2.7.0' gem 'listen', '2.8.6' gem 'guard-rspec', '4.2.8' 

I think it is as good as it is now. I filed a security error .

+1
source

I use Vagrant on MacOS to develop rails applications. I use NFS to sync btwn folders with my Mac (host) and Virtualbox Vm (guest). I ran into many problems when trying to use GAME LISTEN on my Mac to send notifications about changes to the file system in GUARD in the virtual machine.

For me, the best solution was to change the synchronization method of the folder in Vagrant to "rsync", as described here . Now, since the files are actually located on the virtual machine, the latest version of Guard works fine, and there is no complicated transfer of file system changes on the host to the virtual machine using tcp.

The only problem that I have observed so far is that the synchronization of btwn mac and VM does not occur instantly, especially if there is a large (synchronized with you) folder with large sizes. For me, the delay is acceptable (1-2 seconds).

0
source

I also had the same problems, and I solved the problem simply by installing: https://github.com/mhallin/vagrant-notify-forwarder Which automatically sends the fs file to vagrant vm

Hope this helps

0
source

Source: https://habr.com/ru/post/983073/


All Articles