rails s
実行時に下記のようなErrorが発生して少しハマったので、メモφ(..)
Memo
事象
rails s
実行時に下記Errorが発生し、ローカルでWebサーバーが起動しなくなってしまった(T_T)
$ rails s => Booting Puma => Rails 5.1.3 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.10.0 (ruby 2.4.0-p0), codename: Russell's Teapot * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Exiting .rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.10.0/lib/puma/binder.rb:270:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
解決策
Errorメッセージを見てみると、すでに0.0.0.0:3000
が使われてしまっているとのことなので、lsof -i:3000
でポート3000番を使用しているプロセスを確認
$ lsof -i:3000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ruby 1090 hoge 19u IPv4 0xbf3ec388665ab961 0t0 TCP *:hbci (LISTEN) ruby 1090 hoge 24u IPv4 0xbf3ec388655a2ef1 0t0 TCP localhost:hbci->localhost:63436 (CLOSE_WAIT) ruby 1090 hoge 25u IPv4 0xbf3ec388656663d1 0t0 TCP localhost:hbci->localhost:63438 (CLOSE_WAIT) Google 59176 hoge 132u IPv4 0xbf3ec38866494231 0t0 TCP localhost:64018->localhost:hbci (ESTABLISHED)
確かにrubyのプロセスが既に起動してしまっているようなので、killします。
$ kill -9 1090 $ lsof -i:3000 # 結果なし
0.0.0.0:3000
のプロセスがkillされたので、再度rails s
を実行します。
$ rails s => Booting Puma => Rails 5.1.3 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.10.0 (ruby 2.4.0-p0), codename: Russell's Teapot * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://0.0.0.0:3000 Use Ctrl-C to stop Started GET "/users" for 127.0.0.1 at 2018-04-07 13:44:58 +0900
正常に起動しました(・∀・)