Ruby
Rails

Rails sのプロセスが切れない時

サーバー起動すると以下が出た時の対処を定石どおりにやった。

$ rails s
=> Booting Puma
=> Rails 5.0.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
A server is already running. Check プロジェクト名/tmp/pids/server.pid.
Exiting

$ ps ax | grep rails
37580 s001  S+     0:00.01 grep rails

$ kill -9 37580
-bash: kill: (37580) - No such process

No such processと怒られる。なんでやねん。

面倒臭いので /tmp/pids/server.pid.を削除してみた

$ rm /tmp/pids/server.pid

$ rails s
=> Booting Puma
=> Rails 5.0.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Exiting
/Users/fndm40/freeze/freezefoods/vendor/bundle/ruby/2.3.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)

以下エラーメッセージ

なんでやねん!!!!!!!!

めんどいけど、これで解決

$ lsof -wni tcp:3000
COMMAND    PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google     409 fndm40  156u  IPv4 0xf4f2b081d54b7cbf      0t0  TCP 127.0.0.1:61388->127.0.0.1:hbci (ESTABLISHED)
ruby      1091 fndm40   20u  IPv4 0xf4f2b081c673bcbf      0t0  TCP *:hbci (LISTEN)
ruby      1091 fndm40   26u  IPv4 0xf4f2b081d574ceaf      0t0  TCP 127.0.0.1:hbci->127.0.0.1:60305 (CLOSE_WAIT)
ruby      1091 fndm40   28u  IPv4 0xf4f2b081d48de3c7      0t0  TCP 127.0.0.1:hbci->127.0.0.1:61388 (ESTABLISHED)

$ kill -9 1091

$ rails s

"_人人人人人人人人人人人_"
">     無事起動!     <"
" ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄"

終わりに

Railsのサーバーはよくバグる