LoginSignup
274
211

More than 3 years have passed since last update.

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

Last updated at Posted at 2017-12-05

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


$ 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と怒られる。なんでやねん。

追記(2019/8/7)

プロセスのgrep時のやり方を変えればプロセスが無いことがわかりますね。

普通にgrepすると検索したプロセスまで表示されちまいます。

$ ps ax | grep [r]ails

こうするとプロセスが出てこないのがわかるはず。

面倒臭いので /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/user/your_project/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)

以下エラーメッセージ

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

追記 (2019/8/7)

プロセスのgrep時に puma を指定して出てきたプロセスを切ってしまえば、もしかしたら下で記述している lsof コマンドを使わなくてもいけるかもしれません。


$ ps aux | grep [p]uma

$ kill -9 <出てきたプロセス番号>

一度お試しくださいー。

これで解決


$ 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のサーバーはよくバグる

(2019/05/17現在: みんなどんだけプロセス切れないんだ。。。)

274
211
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
274
211