Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
Sometimes it happens that the tmp/pids folder gets lost on the local machine. It is in gitignore for obvious reasons. As a result, the server cannot start and shows the error:
* Listening on http://0.0.0.0:3000bundler: failed to load command: puma (/Users/memecode/.rbenv/versions/3.3.5/bin/puma)/Users/memecode/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/puma-6.5.0/lib/puma/launcher.rb:316:in `write': No such file or directory @ rb_sysopen - tmp/pids/server.pid (Errno::ENOENT)
The error message is quite literal:
No such file or directory @ rb_sysopen - tmp/pids/server.pid
Let's fix the error
We need to create the tmp/pids folder manually. To do this, you can run the following command in the terminal:
mkdir -p tmp/pids
We restart the server, and it should successfully start by creating the server.pid file.
Out of curiosity, you can check:
ls tmp/pids
It should show the file:
server.pid
What is server.pid for?
The server.pid file is used by the Rails server to store the process identifier (PID) of the active server process. This PID helps the system track which process is responsible for the server. Before starting a new server, Rails checks for the existence of this file. If the file exists and the process it points to is still active, Rails does not allow starting a new server to avoid conflicts.
In other words, this is what prevents you from accidentally starting a second server using rails s in a neighboring terminal tab.
Additionally, the file helps properly shut down the server. When the server stops, the server.pid file is automatically deleted, signaling that the server is no longer running and can be restarted without issues. If the file is missing, Rails creates it upon startup. In the case where the file exists but the process it refers to is no longer active, this may cause an error, and then the file needs to be deleted manually before restarting the server.
This post doesn't have any additions from the author yet.