[Ruby] Quickly resolve A server is already running (rails s process cannot be terminated)

1 minute read

**We have compiled several types of solutions when you get the following when trying to start the server! It can be solved by either (should).

❯ rails s
=> Booting Puma
=> Rails 5.0.7.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
A server is already running. Check project name /tmp/pids/server.pid.
Exiting

There are many types, so if you’re having trouble, we recommend that you try them in order.

Check first

Occasionally, there are ``server startup status on Mac standard terminal & trying to start server on a text editor terminal such as VSCode`. First, check if you are already running the server in another terminal**!

Pattern ①

Delete the rails process

$ rails s
=> Booting Puma
=> Rails 5.0.7.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
A server is already running. Check project name /tmp/pids/server.pid.
Exiting

$ ps aux | grep rails
user 28321 s001 S+ 0:00.00 grep rails

$ kill -9 28321

$ rails s
→ resolution

Pattern ②

Delete process with port number 3000

$ lsof -wni tcp:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 28295 user 21u IPv4 0x77d8a30cabb79cc9 0t0 TCP 127.0.0.1:hbci (LISTEN)
ruby 28295 user 22u IPv6 0x77d8a30cac93f9f9 0t0 TCP [::1]:hbci (LISTEN)

# Copy the PID of the line that says "ruby" in "COMMAND" and stop processing (this time 28295)
$ kill -9 28295

$ rails s
→ resolution

Pattern ③

Delete the ID used when starting the server

$ rm /tmp/pids/server.pid

$ rails s
→ resolution

The location of this file is in [app name]/tmp/pids/server.pid, so specify the path and delete it. Originally, when you quit the server, this file is deleted, but it seems that there is a possibility that it remains an error. *Since server.pid is created or deleted by starting and stopping the server, you don’t have to worry about it.

Summary

The kill -9 ○○ that appears frequently is one of the Linux commands, and is for killing processes. Personally, I feel that Pattern ② can often end the process easily.

If you stop by starting the server, it will be withered, so please solve it quickly!

Tags: ,

Updated: