2

I had a new Rails app up and running with Vagrant, with the forward port set to 3000 like this in the Vagrant file

config.vm.forward_port 3000, 3000

After I shut down the server and exited vagrant I got this output `Connection to 127.0.0.1 closed,' however when I tried to start my Rails app without using Vagrant it's telling me

[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>'

A google search told me that I should do this

ps ax | grep ruby

and then kill the process but I was told there wasn't process with the number returned by grep.

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

If this is connected to my use of Vagrant, any idea how I can fix the problem?

Update

Trying the command lsof -wni tcp:3000 found at this SO answer TCPServer Error: Address already in use - bind(2) also failed to kill the process

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
Community
  • 1
  • 1
Leahcim
  • 40,649
  • 59
  • 195
  • 334
  • note, I got the server to start by passing the `-p` option to the rails server command and setting it to a different port (3001) but I would still like to know how I can get it to work on port 3000 – Leahcim Jul 30 '13 at 19:38
  • You can do `config.vm.forward_port 3000, 3000, auto_correct: true` to have vagrant choose a different port (I think 2200) if it collides with something at 3000. You might want to check if you have a rogue vagrant machine running. – bfitzpatrick Jul 30 '13 at 21:01
  • Looks like some other process is using port 3000. What is the outptu of `netstat -nap | grep :3000`? Base on the `lsof` output, VBoxHeadless is binding to all interfaces on port 3000. Its PID is 601. You can probably do a `ps -ef | grep 601` or `cat /proc/601/cmdline` to see the complete command line. NOTE: the PID may change. – Terry Wang Jul 30 '13 at 21:29
  • @TerryWang output of netstat was `netstat: option requires an argument -- p` seems like the command's missing an argument – Leahcim Jul 31 '13 at 01:21
  • Did you use 'netstat -nap | grep :3000'? They are all generic arguments, should work anyway. – Terry Wang Jul 31 '13 at 01:24
  • @TerryWang did exactly that command – Leahcim Jul 31 '13 at 01:40

0 Answers0