Sometimes the rails server couldn't start while proceeding with the Rails tutorial. The bottom line was that I thought I was quitting the rails server, but I couldn't quit it, and I couldn't start it again because it was still running. As a memorandum, I have summarized the cases where rails server could not be terminated and how to terminate it.
Look up the rails server process number with the option aux on the ps command. The process whose last COMMAND item is the Rails app name is the corresponding process.
$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ----
hoge 31701 15.0 0.2 1095324 70456 tty15 Sl 12:00 0:01 puma 4.3.4 (tcp: // localhost: 3000) [app name] ----
Kill this process with the kill command.
$ kill 31701
The process number is also listed in the following file. View the contents with the cat command.
$ cat tmp/pids/server.pid 31701
Pipe the result of ps to grep to make it easier to find the process
When you accidentally quit with Ctrl + Z etc., it looks like it's quit, but Rails server is still running.
$ rails s => Booting Puma => Rails 6.0.3 application starting in development => Run `rails server --help` for more startup options Puma starting in single mode... * Version 4.3.4 (ruby 2.7.1-p83), 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 ^Z + Stopped rails s
Look up the process number and execute the kill command with option -9, as in "When you close the terminal window without Ctrl + C". The process may not end without the option.
$ kill -9 31701
Quickly drop Rails server process