Unable to start rails server - ruby-on-rails

I am trying to start rails server using rails s command. But i'm getting the following error:
A server is already running. Check repo/tmp/pids/server.pid.
I checked the file, but its blank. There is no id in the server.pid file. Then I tried to find out the process running on port 3000 using the command lsof -wni tcp:3000. It also does not show any id.
Then I tried starting the server on a different port using rails s -p 3001, but this also gives the same error. Please could someone explain what is going on.
Thanks
EDIT: does not work even after restarting computer

Just remove the file then:
rm repo/tmp/pids/server.pid

Try running this command in your terminal window.
kill -9 $(lsof -i tcp:3000 -t)
If it doesn't work, you can always just restart your computer/server...

1- Use the command below for checking that how many server currently running
$ ps aux | grep rails
2- For killing the existing server
$ kill -9 pid

Related

localhost:3000 not working in browser (Rails 7)

i typed rails s in the terminal and everything was working fine,
as my rails server was running i by mistakely pressed ctrl+z on the keyboard and next time when i tried to run rails s , my terminal was showing an error
A server is already running. Check /home/..name/rprojects/railsapp/tmp/pids/server.pid.
so i checked other solutions on stackoverflow itself and i found out we need to delete the server.pid. file present inside it.
after when i deleted the server.pid. file and typed rails s to start the server in the terminal, my browser keeps on loading the http://localhost:3000/ and does not render anything, it just keeps on loading and nothing happens
so then i typed rails s -p 3001 in the terminal and it started working fine and everything is working normally on 3001 port
So how do i fix the loading problem on 3000 port when i run rails s in terminal and infinite loop of loading occurs and nothing happens??
even if i did not start the rails server in terminal and went on browser and typed http://localhost:3000/ , it keeps on loading and nothing shows
You must kill the process by the PID which is in server.pid
sudo kill -9 PID
ex: the PID is 1000
sudo kill -9 1000
because you started another rails s, the PID was replaced.
You can run this cmd to find the PID of rails s
ps aux | grep rails
I offen use this command line
sudo kill -9 $(sudo lsof -t -i:3000) ( 3000 is port)
Enter password
restart server

rails s command is starting the wrong application

Bit of a strange problem. I'm in ~/My Programs/app2. I run 'rails s' and it starts the application located in ~/My Programs/app1 on localhost:3000. Any idea why this might be happening?
No error messages..
I am thinking that your server for app1 is still running
try rails s -p 4000
and go to localhost:4000 that should bring you to your app
Remove rails detached server by using command
ps -aef | grep rails
OR by this command
lsof -wni tcp:3000
then
kill -9 pID

Rails server start/stop

To run the Rails server, I use $rails server. It says 'To stop, click Ctrl+c'.
I use Putty.
The questions are:
Should I keep the terminal open always? Because if the server stops, my web page wouldn't work. With Apache I just used commands apachectl start/stop.
What if I want to use a command? Should I stop the server, use command, and run again? Because in the same terminal I can't do enything if the server run.
you can run it in background by writing
daemonize true
in your puma.rb file
To stop you need to find your running puma process
ps aux | grep puma
then you need to kill the main process
sudo kill -9 your process id
to start you need to type
puma -C config/puma.rb
You can start a daemonized server by adding -d to your command. For instance:
rails server -d
To stop the server, you can kill it based on its process id:
kill $(cat tmp/pids/server.pid)
Should I keep the terminal open always? Because if the server stops, my web page wouldn't work. With Apache I just used commands apachectl start/stop.
Yes, you should keep it open because if you Ctrl C it will stop the server. Another option is to run it in the background but I'm not sure how to do that in Putty.
What if I want to use a command? Should I stop the server, use command, and run again? Because in the same terminal I can't do enything if the server run.
Can you open another terminal window? If you have two terminal windows you can use one for running the server and another for other tasks.

Unable to start webbrick again without restarting ec2 instance

I am running a rails 3.2 application on amazon ec2 in development environment and detach mode.
$ rails s -d
After this command the ec2 terminal hangs and does not come out of this command but the server starts as I can access the application.I have to close the terminal and the server remains started.
After this I kill the application.
$ lsof|grep 3000
$ kill -9 <pid>
Now if I try to restart the server, it gives error.
A server is already running. Check /home/ubuntu/trade_ship/tmp/pids/server.pid.
Exiting
Now even if I delete the tmp folder and recreate it, the server won't start. Can anyone help me with these two issues?
Even I had faced that issue, try to restart your system and then check.. this solution worked for me at that time.
First of all if you are not able to use port 3000 use rails s -p <port no> command
Second is if you have to kill the RUBY instance which server started so use
ps aux | grep ruby
username 17731 0.1 1.6 3127008 67996 ?? S 2:00PM 0:01.42 /Users/username/.rvm/rubies/ruby-1.9.2-p180/bin/ruby script/rails s -d
and then kill
kill -9 17731
This will definitely solve the issue

Server is already running in Rails

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).
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
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.
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.
kill -9 $(lsof -i tcp:3000 -t)
You can get rid of the process by killing it:
kill -9 $(lsof -i tcp:3000 -t)
$ lsof -wni tcp:3000
# Kill the running process
$ kill -9 5946
$ rm tmp/server.pids
foreman start etc start the service
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
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>
On Windows Rails 5.2, delete this file
c:/Sites/<your_folder>/tmp/pids/server.pid
and run
rails s
again.
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
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.
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
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.
Run: fuser -k -n tcp 3000
This will kill the process running at the default port 3000.
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
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.
my docker container has no lsof. Try sudo kill -9 $(netstat -ano -p tcp | grep :3000 | awk '{ print $7 }' | grep -Po '^[\d]+')
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
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.
I was after a way I could intuitively understand (as opposed to just memorise).
All you need to know is two things
Run the ps command to list processes, and
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.

Resources