rails s で「WARN TCPServer Error: Address already in use - bind(2)」エラー
Rails サーバを起動しようとしたらエラーがでました。
こんな感じです。
$ rails s => Booting WEBrick => Rails 3.1.3 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-01-12 13:49:02] INFO WEBrick 1.3.1 [2012-01-12 13:49:02] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0] [2012-01-12 13:49:02] WARN TCPServer Error: Address already in use - bind(2) Exiting /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE) from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/utils.rb:85:in `new' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/utils.rb:85:in `block in create_listeners' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/utils.rb:82:in `each' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/utils.rb:82:in `create_listeners' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:82:in `listen' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:70:in `initialize' from /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:45:in `initialize' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/handler/webrick.rb:10:in `new' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/handler/webrick.rb:10:in `run' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.5/lib/rack/server.rb:265:in `start' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands/server.rb:70:in `start' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:54:in `block in <top (required)>' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:49:in `tap' from /Users/shiori/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/commands.rb:49:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
これの原因なのですが、どこかでWEBrickを使用していたりすることが原因みたいです。
自分の場合は、Rubyサーバが動いていたことが原因でした。
・・・起動した覚えがないんだけどな。
プロセス確認は次のようにしてみましょう。
$ lsof -i:3000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ruby 2181 shiori 9u IPv4 0x11ba7338 0t0 TCP *:hbci (LISTEN)
WEBrickだと、Ruby関係が多いので次でも確認ができます。
$ ps -af | grep ruby 501 2181 2111 0 2:02PM ttys001 0:03.27 /Users/shiori/.rvm/rubies/ruby-1.9.3-p0/bin/ruby script/rails s
プロセスをkillしてあげれば問題なく動きます。
kill -9 2181