0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Rails「A server is already running. Check /Users/me/environment/XXX/tmp/pids/server.pid.」の解決方法

Last updated at Posted at 2023-05-01

パソコンを再起動してrails serverを実行したところ、以下のエラーが起こりました。解決方法を残します。

$ rails server
=> Booting Puma
=> Rails 7.0.4.3 application starting in development 
=> Run `bin/rails server --help` for more startup options
A server is already running. Check /Users/me/environment/XXX/tmp/pids/server.pid.

再起動時にctrl + Cでサーバーをシャットダウンしていなかったので、プロセスが残ったままになってしまったことが原因だと考えられます。

まずはこちらの記事の通り、XXX/tmp/pidsフォルダに有るserver.pidファイルを削除しました。
次にlsof -i:3000で実行中のプロセスを確認し、こちらの記事の通りkill 1489を実行しましたが、プロセスが消えませんでした。

$ lsof -i:3000
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google     516   me   34u  IPv6 0x6e4255ffacc03f29      0t0  TCP localhost:49915->localhost:hbci (ESTABLISHED)
ruby      1489   me   10u  IPv4 0x6e4255ffb1aa5b89      0t0  TCP localhost:hbci (LISTEN)
ruby      1489   me   11u  IPv6 0x6e4255ffbaeb1be9      0t0  TCP localhost:hbci (LISTEN)
ruby      1489   me   18u  IPv6 0x6e4255ffacc04be9      0t0  TCP localhost:hbci->localhost:49727 (CLOSE_WAIT)
ruby      1489   me   19u  IPv6 0x6e4255ffacc05249      0t0  TCP localhost:hbci->localhost:49728 (CLOSE_WAIT)
ruby      1489   me   20u  IPv6 0x6e4255ffbaeb2249      0t0  TCP localhost:hbci->localhost:49749 (CLOSE_WAIT)
ruby      1489   me   21u  IPv6 0x6e4255ffacc058a9      0t0  TCP localhost:hbci->localhost:49779 (CLOSE_WAIT)
ruby      1489   me   22u  IPv6 0x6e4255ffb4983f29      0t0  TCP localhost:hbci->localhost:49780 (CLOSE_WAIT)
$ kill 1489
$ lsof -i:3000
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google     516   me   34u  IPv6 0x6e4255ffacc03f29      0t0  TCP localhost:49915->localhost:hbci (ESTABLISHED)
ruby      1489   me   10u  IPv4 0x6e4255ffb1aa5b89      0t0  TCP localhost:hbci (LISTEN)
ruby      1489   me   11u  IPv6 0x6e4255ffbaeb1be9      0t0  TCP localhost:hbci (LISTEN)
ruby      1489   me   18u  IPv6 0x6e4255ffacc04be9      0t0  TCP localhost:hbci->localhost:49727 (CLOSE_WAIT)
ruby      1489   me   19u  IPv6 0x6e4255ffacc05249      0t0  TCP localhost:hbci->localhost:49728 (CLOSE_WAIT)
ruby      1489   me   20u  IPv6 0x6e4255ffbaeb2249      0t0  TCP localhost:hbci->localhost:49749 (CLOSE_WAIT)
ruby      1489   me   21u  IPv6 0x6e4255ffacc058a9      0t0  TCP localhost:hbci->localhost:49779 (CLOSE_WAIT)
ruby      1489   me   22u  IPv6 0x6e4255ffb4983f29      0t0  TCP localhost:hbci->localhost:49780 (CLOSE_WAIT)

そこでこちらの記事の通り、kill -9 1489を実行すると消すことができ、サーバーを起動できました。

$ kill -9 1489
$ lsof -i:3000
$ rails server
=> Booting Puma
=> Rails 7.0.4.3 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.1.3-p185) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 7011
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?