Server is already running in Rails
Ruby on-RailsRuby on-Rails-3.2Command PromptWebrickRuby on-Rails Problem Overview
When I am starting rails server using rails s
command it is showing A server is already running. Check C:/Sites/folder/Pids/Server.pids
When I open the file it is outputting a 4 digit number only so how could I resolve this issue ?
FYI
- No other instance of Rails cmd is running this time.
- Checked Task manager but only
cmd.exe
is showing no else process is running. (using Windows).
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
TL;DR Just Run this command to Kill it
sudo kill -9 $(lsof -i :3000 -t)
Root Cause: Because PID is locked in a file and web server thinks that if that file exists then it means it is already running. Normally when a web server is closed that file is deleted, but in some cases, proper deletion doesn't happen so you have to remove the file manually New Solutions
when you run rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on http://0.0.0.0:3000
=> Run rails server -h
for more startup options
=> Ctrl-C to shutdown server
A server is already running. Check /your_project_path/tmp/pids/server.pid. Exiting
So place your path shown here /your_project_path/tmp/pids/server.pid
and remove this server.pid file:
rm /your_project_path/tmp/pids/server.pid
OR Incase you're server was detached then follow below guidelines:
If you detached you rails server by using command "rails -d" then,
Remove rails detached server by using command
ps -aef | grep rails
OR by this command
sudo lsof -wni tcp:3000
then
kill -9 pID
OR use this command
To find and kill process by port name on which that program is running. For 3000 replace port on which your program is running.
sudo kill -9 $(lsof -i :3000 -t)
Old Solution:
rails s -p 4000 -P tmp/pids/server2.pid
Also you can find this post for more options https://stackoverflow.com/questions/14329370/rails-update-to-3-2-11-breaks-running-multiple-servers
Solution 2 - Ruby on-Rails
Remove the file: C:/Sites/folder/Pids/Server.pids
Explanation In UNIX land at least we usually track the process id (pid) in a file like server.pid. I think this is doing the same thing here. That file was probably left over from a crash.
Solution 3 - Ruby on-Rails
lsof -wni tcp:3000
Then you should see the ruby process and you can run
kill -9 processid
you should be good to run the process now
rails s thin
running multiple processes doesn't seem like a good idea and from what i've read many people agree. I've noticed many memory leaks with rails unfortunately so I couldn't imagine having two processes running. I know with one overtime my page refreshes increasingly become slower because of the data being stored on memory.
Solution 4 - Ruby on-Rails
kill -9 $(lsof -i tcp:3000 -t)
Solution 5 - Ruby on-Rails
You can get rid of the process by killing it:
kill -9 $(lsof -i tcp:3000 -t)
Solution 6 - Ruby on-Rails
$ lsof -wni tcp:3000
# Kill the running process
$ kill -9 5946
$ rm tmp/server.pids
foreman start etc start the service
Solution 7 - Ruby on-Rails
gem install shutup
then go in the current folder of your rails project and run
shutup
# this will kill the Rails process currently running
You can use the command 'shutup' every time you want
DICLAIMER: I am the creator of this gem
NOTE: if you are using rvm install the gem globally
rvm @global do gem install shutup
Solution 8 - Ruby on-Rails
It happens when you kill your server process and the pid file was not updated. The best solution is to delete the file Server.pid.
Use the command
> rm <path to file Server.pid>
Solution 9 - Ruby on-Rails
Probably you suspended the server by: ^Z
.
The four digital number that vim C:/Sites/folder/Pids/Server.pids
outputs is the process id.
You should kill -9 processid
, replacing the process id with the 4 numbers that vim (or other editor) outputed.
Solution 10 - Ruby on-Rails
On Windows Rails 5.2, delete this file
c:/Sites/<your_folder>/tmp/pids/server.pid
and run
rails s
again.
Solution 11 - Ruby on-Rails
If you are on Windows, you just need to do only one step as 'rails restart' and then again type 'rails s' You are good to go.
Solution 12 - Ruby on-Rails
Run:
in Ubuntu/linux
sudo rm /var/www/html/rails/WBPOCTEST/tmp/pids/server.pid
Or
pkill -9 ruby
or
lsof -wni tcp:3000
kill -9 pid
Solution 13 - Ruby on-Rails
Run: fuser -k -n tcp 3000
This will kill the process running at the default port 3000.
Solution 14 - Ruby on-Rails
> Just open that C:/Sites/folder/Pids/Server.pids and copy that 4 digit > value.that 4 digit value is nothing but a PID, which you need to kill > to stop the already running process.
then to stop the process use below command
kill -9 <pid>
once that already running process get stopped then hit
rails s
to start the rails server
Solution 15 - Ruby on-Rails
I just had this issue and tried setting it to a different port, but the only thing I needed to do was to delete my [app_directory]/tmp/pids/server.pid
and everything was good to go.
Solution 16 - Ruby on-Rails
On Ubuntu :-
sudo kill -9 $(lsof -i :3000 -t)
where,
3000 is port number
Works for me....
For older versions :-
rails s -p 3000 -P tmp/pids/server2.pid
Solution 17 - Ruby on-Rails
my docker container has no lsof
. Try sudo kill -9 $(netstat -ano -p tcp | grep :3000 | awk '{ print $7 }' | grep -Po '^[\d]+')