Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A server is already running. Check …/tmp/pids/server.pid. Exiting - rails

..$ 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 /home/..name/rprojects/railsapp/tmp/pids/server.pid.
Exiting

what is the easiest way to solve this for a rails beginner?

like image 929
ben Avatar asked Jul 08 '14 09:07

ben


13 Answers

You can delete the server.pid file.

rm /your_project_path/tmp/pids/server.pid

Else:

try in OSX:

sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000

or in linux:

ps -aef | grep rails

or

lsof -wni tcp:3000

kill the process using

kill -9 PID (eg,2786)
like image 117
ben Avatar answered Oct 02 '22 13:10

ben


Short and Crisp single line command, that will take care of it.

kill -9 $(lsof -i tcp:3000 -t)
like image 41
Karan Purohit Avatar answered Sep 29 '22 13:09

Karan Purohit


server.pid only contains the process ID of the running server.

If you do:

more /your_project_path/tmp/pids/server.pid

you will get a number (say 6745) which you can use to stop the previous server with the command kill:

kill -9 6745

and then you can remove the file with the rm command

rm /your_project_path/tmp/pids/server.pid
like image 34
muichkine Avatar answered Oct 03 '22 13:10

muichkine


If you are using docker-compose, and in docker-compose.yml have: volumes: - .:/myapp That means you local workspace is mapped to the container's /myapp folder.

Anything in /myapp will not be deleted for the volumes define.

You can delete ./tmp/pids/server.pid in you local machine. Then the container's /myapp will not have this file.

like image 37
Lane Avatar answered Sep 29 '22 13:09

Lane


Simple:

go in the root folder of the project when this happens and run:

gem install shutup
shutup

This will find the process currently running, kill it and clean up the pid file

NOTE: if you are using rvm install the gem globally

rvm @global do gem install shutup
like image 20
Lorenzo Sinisi Avatar answered Oct 01 '22 13:10

Lorenzo Sinisi


Run this command -

lsof -wni tcp:3000

then you will get the following table -

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ruby    2552 shyam   17u  IPv4  44599      0t0  TCP 127.0.0.1:3000 (LISTEN)
ruby    2552 shyam   18u  IPv6  44600      0t0  TCP [::1]:3000 (LISTEN)

Run this command and replace PID from the Above table

kill -9 PID

example:

kill -9 2552
like image 21
Pradnyesh patil Avatar answered Sep 30 '22 13:09

Pradnyesh patil


Issue can be solved using:

kill -9 $(more /home/..name/rprojects/railsapp/tmp/pids/server.pid)
like image 36
webster Avatar answered Oct 03 '22 13:10

webster


It happens sometimes because you turn off the server by force, for example turning off the OS/machine manually so that the server does not have enough time to log to server.pid.

One easy way is to manually go to tmp/pids/ (the directory that is shown in your console.) and remove server.pid file. Then, when you start the server again, rails server or rails s ,it creates a new server.pid and you can continue development.

like image 28
DragonKnight Avatar answered Oct 02 '22 13:10

DragonKnight


First Find PID # - where the Rails Server got stuck on

Run this to find the stuck PID

cat ./tmp/pids/server.pid

It will return something like 65829

Then KILL that PID => kill 65829

like image 25
Jonathan Sanchez Avatar answered Sep 29 '22 13:09

Jonathan Sanchez


Kill server.pid by using command:

kill -9 `cat /root/myapp/tmp/pids/server.pid`

Note: Use your server.pid path which display in console/terminal.

Thank you.

like image 40
Rahul2692 Avatar answered Oct 03 '22 13:10

Rahul2692


the gui way for Windows user

open the ResourceMonitor (taskmanager ->Performance -> ResourceMonitor) and kill the ruby.exe process

enter image description here

like image 37
Alexander Sidikov Pfeif Avatar answered Oct 02 '22 13:10

Alexander Sidikov Pfeif


For added information, under the context of running the application in docker.

In docker-compose.yml file, under the application container itself, you can use one of the following:

command: ["rm /your-app-path/tmp/pids/server.pid && bundle exec bin/rails s -p 3000 -b '0.0.0.0'"]

or

command: ["rm /your-app-path/tmp/pids/server.pid; foreman start"]

Note the use of either ; or &&, that && will send an exit signal if rm fails to find the file, forcing your container to prematurely stop. Using ; will continue to execute.

Why is this caused in the first place? The rationale is that if the server (puma/thin/whatever) does not cleanly exit, it will leave a pid in the host machine causing an exit error.

For portability rather than manually deleting the file on the host system, it's better to check if the file exists within scripted or compose file itself.

like image 37
mirageglobe Avatar answered Sep 29 '22 13:09

mirageglobe


Open the path/to/your/rails/project/tmp/pids/server.pid file.

Copy the number you find therein.

Run kill -9 [PID]

Where [PID] is the number you copied from the server.pid file.

This will kill the running server process and you can start your server again without any trouble.

like image 27
Daniel Okwufulueze Avatar answered Sep 29 '22 13:09

Daniel Okwufulueze