Server is already running in Rails
Asked Answered
B

21

172

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

  1. No other instance of Rails cmd is running this time.
  2. Checked Task manager but only cmd.exe is showing no else process is running. (using Windows).
Blab answered 25/2, 2013 at 17:32 Comment(1)
I remover server.pid from \tmp\pidsBacchius
B
222

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.

Blinkers answered 25/2, 2013 at 17:34 Comment(7)
what exactly this file do and cause for this ..can you please explain it a little more :)Blab
Sorry, I should have commented further. 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.Blinkers
I think I clone it from Git so do u think it might be a cause ? github.com/swapnesh/Add_twitter_bootstrapBlab
After doing this I'm still getting a "Port in use" for 3000. Anyone know how I can fix this? Thanks!Thymic
Run netstat -a -o at a command prompt to see what process is using port 3000Insular
causes socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE), check joshs answer how to resolve this after removing .pidForethought
its /tmp/pids nowDerbyshire
G
262

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 Rails Update to 3.2.11 breaks running multiple servers

Gooding answered 18/4, 2013 at 6:26 Comment(4)
because PID is locked in file and web server thinks that if that file exists then it means it is already running. Normally when web server is closed that file is deleted, but in some cases proper deletion don't happen so you have to remove file manuallyGooding
Careful this will also kill your browser if it's pointing to :3000!Spitz
perfect solution for sudo kill -9 $(lsof -i :3000 -t)Masquer
Very nice! I created a function on my bash profile that kill the running server using this command, so you just type kill_server on the terminal and everything is done. I declared this on my bash profile: kill_server() { sudo kill -9 $(lsof -i :3000 -t) }Atrocity
B
222

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.

Blinkers answered 25/2, 2013 at 17:34 Comment(7)
what exactly this file do and cause for this ..can you please explain it a little more :)Blab
Sorry, I should have commented further. 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.Blinkers
I think I clone it from Git so do u think it might be a cause ? github.com/swapnesh/Add_twitter_bootstrapBlab
After doing this I'm still getting a "Port in use" for 3000. Anyone know how I can fix this? Thanks!Thymic
Run netstat -a -o at a command prompt to see what process is using port 3000Insular
causes socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE), check joshs answer how to resolve this after removing .pidForethought
its /tmp/pids nowDerbyshire
S
88
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.

Spang answered 13/3, 2014 at 18:58 Comment(0)
F
30
kill -9 $(lsof -i tcp:3000 -t)
Feola answered 24/2, 2015 at 12:26 Comment(1)
@CalamityAdam Rails usually runs on port 3000. He searches for processes based on that and gets only the PID from them (-t option) and then kills the process by that retrieved PID.Side
S
15

You can get rid of the process by killing it:

kill -9 $(lsof -i tcp:3000 -t)
Smoothie answered 27/3, 2018 at 13:38 Comment(1)
I like this one. Nice and concise, yet complete. Cheers.Steamship
H
12
$ lsof -wni tcp:3000

# Kill the running process
$ kill -9 5946

$ rm tmp/server.pids

foreman start etc start the service

Houstonhoustonia answered 8/6, 2016 at 3:5 Comment(0)
P
7

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
Perambulator answered 16/11, 2016 at 11:51 Comment(0)
A
5

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>

Actiniform answered 28/8, 2013 at 11:19 Comment(0)
A
4

On Windows Rails 5.2, delete this file

c:/Sites/<your_folder>/tmp/pids/server.pid

and run

rails s

again.

Airmail answered 17/9, 2018 at 23:48 Comment(0)
E
4

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

Elamite answered 28/11, 2020 at 3:49 Comment(0)
M
3

Probably you suspended the server by: ^Z.

The four digital number that vim C:/Sites/folder/Pids/Server.pidsoutputs is the process id.

You should kill -9 processid, replacing the process id with the 4 numbers that vim (or other editor) outputed.

Megalopolis answered 20/7, 2015 at 3:24 Comment(1)
What's the right way to stop the server properly? CTRL + C?Tumpline
H
3

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
Hershel answered 16/1, 2019 at 8:31 Comment(0)
F
3

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

Fustian answered 10/8, 2021 at 10:12 Comment(0)
D
2

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.

Dateless answered 3/11, 2017 at 8:18 Comment(0)
E
1

Run: fuser -k -n tcp 3000

This will kill the process running at the default port 3000.

Epididymis answered 6/9, 2018 at 23:20 Comment(0)
D
0

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.

Denison answered 28/12, 2018 at 21:58 Comment(0)
T
0

my docker container has no lsof. Try sudo kill -9 $(netstat -ano -p tcp | grep :3000 | awk '{ print $7 }' | grep -Po '^[\d]+')

Therine answered 7/10, 2021 at 9:21 Comment(0)
S
0

I have face this issue in my rails application when i used docker in windows mechine. i just removed the server.pid file from the project and restart the rails application.

You just need to delete C:/Sites/folder/Pids/Server.pid this file

Sparge answered 23/8, 2022 at 7:1 Comment(0)
T
0

Just go to the TMP folder in your application. Go to the pids folder and delete the files present. Now rerun the server. This worked for me.

Tonsure answered 7/11, 2022 at 5:44 Comment(0)
H
0

I was after a way I could intuitively understand (as opposed to just memorise).

All you need to know is two things

  1. Run the ps command to list processes, and
  2. Run the kill command to stop a process

Example

Then it's as simple as:

ps
# PID TTY           TIME CMD
# 32953 ttys000    0:00.71 -zsh
# 33730 ttys001    0:00.67 -zsh  
# 46844 ttys004    0:01.78 puma 4.3.12 (tcp://localhost:3000) [myapp] 

look for the PID that matches your rails server, and pass it to kill

kill -9 46844

Run ps again to see that it's now stopped.

Note

  • For more info on -9, run man kill.
Horripilation answered 7/12, 2022 at 14:9 Comment(0)
G
0

A server is already running. Check C:/Sites/folder/Pids/Server.pids

Remove the server.pids file from the directory. Then try starting your rails server again from your terminal.


In the event if the above (deleting the server.pids file) still does not work, try this link. This article shows you if you are still getting the "Address already in use - bind(2) (Errno::EADDRINUSE)" error when starting rails -s.

Guillaume answered 20/11, 2023 at 0:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.