Closed2
"`rails s`でサーバー起動時の"「`A server is already running.`」エラーへの対処
事象
レイルズサーバーを立ち上げようとしたところ、下記エラーが発生
$ bundle exec rails s
=> Booting Puma
=> Rails 6.0.3.4 application starting in development
=> Run `rails server --help` for more startup options
A server is already running. Check /home/masa/environment/RailsTutorial/sample_app2/tmp/pids/server.pid.
Exiting
エラーメッセージには、「サーバーは既に動いているのでsercer.pid
ファイルを確認してください」と出力されている。
対処
エラーメッセージで検索すると、server.pid
ファイルを削除するとよいとあったので、削除。
$ rm [エラーメッセージで出力されたパス]/server.pid
そして再びrailsサーバーを起動しようとするが、エラーとなる。
$ bundle exec rails s
/home/masa/environment/RailsTutorial/sample_app2/vender/bundle/ruby/2.7.0/gems/puma-4.3.7/lib/puma/binder.rb:229:in `initialize':
Address already in use - bind(2) for "127.0.0.1" port 3000 (Errno::EADDRINUSE)
エラーメッセージは、localhost"127.0.0.1"のポート3000は既に使われていると出力されている。
なので、ポート3000で動いているプロセスを探す。
$ lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 3755 masa 13u IPv4 32639 0t0 TCP localhost:3000 (LISTEN)
ruby 3755 masa 14u IPv6 32640 0t0 TCP ip6-localhost:3000 (LISTEN)
そのプロセスをkillする。
$ kill 3755
再び、railsサーバーを起動。
$ bundle exec rails s
=> Booting Puma
=> Rails 6.0.3.4 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.7 (ruby 2.7.2-p137), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
無事、起動できました。
参考
このスクラップは2021/01/11にクローズされました