2

我有一个新的 Rails 应用程序启动并使用 Vagrant 运行,在 Vagrant 文件中将转发端口设置为 3000

config.vm.forward_port 3000, 3000

在我关闭服务器并退出 vagrant 后,我​​得到了这个输出“与 127.0.0.1 的连接关闭”,但是当我尝试在不使用 Vagrant 的情况下启动我的 Rails 应用程序时,它告诉我

[2013-07-30 12:18:41] INFO  WEBrick 1.3.1
[2013-07-30 12:18:41] INFO  ruby 2.0.0 (2013-05-14) [x86_64-darwin12.4.0]
[2013-07-30 12:18:41] WARN  TCPServer Error: Address already in use - bind(2)
Exiting

    /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `new'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `block in create_listeners'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:82:in `each'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:82:in `create_listeners'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:132:in `listen'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:113:in `initialize'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:45:in `initialize'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `new'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `run'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:84:in `start'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
        from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

谷歌搜索告诉我我应该这样做

ps ax | grep ruby

然后终止进程,但我被告知没有 grep 返回的数字的进程。

michael$ ps ax | grep ruby
 3604 s001  R+     0:00.00 grep ruby
michael$ kill -9 3604
-bash: kill: (3604) - No such process

如果这与我对 Vagrant 的使用有关,知道如何解决这个问题吗?

更新

尝试lsof -wni tcp:3000在这个 SO answer 找到的命令TCPServer Error: Address already in use - bind(2)也未能终止进程

michael$ lsof -wni tcp:3000
COMMAND   PID                USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
VBoxHeadl 601 mm   22u  IPv4 0x888bec8d3960ddb1      0t0  TCP *:hbci (LISTEN)
michael$ kill -9 PID
-bash: kill: PID: arguments must be process or job IDs
4

0 回答 0