守卫 --listen-on with vagrant [英] Guard --listen-on with vagrant

查看:36
本文介绍了守卫 --listen-on with vagrant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用守卫的 --listen-on 选项和 vagrant 概述 这里,但我无法让它工作.

I am trying to use guard's --listen-on option with vagrant as outlined here, but I am unable to get it to work.

如果我将 config.vm.network :forwarded_port, guest: 4000, host: 4000 添加到我的 Vagrantfile 并随后尝试使用 listen 开始监听 -f 127.0.0.1:4000,出现错误:Broadcaster.initialize: Address already in use - bind(2) for "127.0.0.1" port 4000.

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 无法转发此 VM 上的指定端口,因为它们会与其他一些已经在监听的应用程序发生冲突在这些端口上.转发到 4000 的端口已被使用在主机上.

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.

所以我尝试了一些其他的东西,同时在 Vagrantfile 中省略了端口 4000 转发:

So I tried some other things while omitting the port 4000 forwarding in the Vagrantfile:

如果我在我的 Vagrantfile 中省略了端口 4000 转发,那么我可以成功地使用 listen -f 127.0.0.1:4000 开始监听.但是当我在我的流浪来宾中运行 guard -o "10.0.2.2:4000" -w "/home/me/my_project/" 时,当文件更改时,guard 不会做任何事情.向 listen 调用添加 -v 标志表明更改正在在主机上正确拾取.

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.

我也在主机上尝试了 listen -f 10.11.12.1:4000 结合 guard -o "10.11.12.1:4000" -w "/home/me/my_project/" 对具有相同结果的来宾,当文件更改时不做任何事情.

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.

结合 listen -f 127.0.0.1:4000guard -o "10.11.12.1:4000" -w "/home/me/my_project/" 结果守卫无法连接.

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.

我也尝试过使用 ssh 进行端口转发:

I've also tried port forwarding with 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

端口转发的一切似乎一切正常,但是当文件被更改时,guard 永远不会做任何事情.

Everything seems to go okay with port forwarding, but again guard never does anything when files are changed.

host 和 guest 都是 ubuntu 14.04.

Both the host and guest are ubuntu 14.04.

我的Vagrantfile中的网络配置如下:

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?

推荐答案

更新 2:

Listen 3.x 不再包含 TCP 功能(请参阅 https://github.com/guard/listen/issues/258),所以你需要锁定到 2.x,例如在您的 Gemfile 中:

Listen 3.x no longer includes TCP functionality (see https://github.com/guard/listen/issues/258), so you'll need to lock to 2.x, e.g. in your Gemfile:

gem 'listen', '~> 2.9'

然后按照以下说明进行操作:

And then follow the instructions below:

更新 1:

要使 guard >= v2.7.0 正常工作,您需要 listen >= v2.9.0 和神奇的 -r 选项(因为主机和来宾的完整路径不匹配):

For guard >= v2.7.0 to work, you need listen >= v2.9.0 and the magic -r option (since full paths don't match on 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)

注意事项:

  • guard v2.7.0 起,-w 仅用于侦听多个目录.相反,在您正在观看的目录中运行 listen

  • since guard v2.7.0, -w is only for listening for multiple directories. Instead, run listen in the directory you're watching

仅当您位于防火墙之后,或者您出于某种原因无法使用给定端口时,我才会考虑使用 Vargrant/ssh 转发 - 而是使用 VM 分配的 IP 和网络(例如 10.11.12.1)

I'd only consider Vargrant/ssh forwarding only if you're behind a firewall, or you can't use the given ports for some reason - instead, use the VM assigned IPs and network (e.g. 10.11.12.1)

要在 guard 中调试内容,请查看:https://github.com/guard/guard/wiki/Understanding-Guard(值得一看)

for debugging things in guard, check out: https://github.com/guard/guard/wiki/Understanding-Guard (worth taking a look)

在 127.0.0.1 上运行侦听 TCP 服务器毫无意义(除非您必须使用复杂的 ssh 端口转发设置)

running a listen TCP server on 127.0.0.1 makes little sense (unless e.g. you must use a complex ssh port forwarding setup)

这篇关于守卫 --listen-on with vagrant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆