I'm on a mac, doing:
rails server
I get:
2010-12-17 12:35:15] INFO WEBrick 1.3.1
[2010-12-17 12:35:15] INFO ruby 1.8.7 (2010-08-16) [i686-darwin10.4.0]
[2010-12-17 12:35:15] WARN TCPServer Error: Address already in use - bind(2)
Exiting
I know I can start one on a new port, but I want to kill this process.
This question is related to
ruby-on-rails
All the answers above are really good but I needed a way to type as little as possible in the terminal so I created a gem for that. You can install the gem only once and run the command 'shutup' every time you wanna kill the Rails process (while being in the current folder).
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
kill -9 $(lsof -i tcp:3000 -t)
Using this command you can kill the server:
ps aux|grep rails
You need to get process id of program using tcp port 3000. To get process id
lsof -i tcp:3000 -t
And then using that process id, simply kill process using ubuntu kill command.
kill -9 pid
Or just run below mentioned combine command. It will first fetch pid and then kill that process.
kill -9 $(lsof -i tcp:3000 -t)
By default, rails server uses port 3000.
So, you have 2 options to run rails server.
1. Either you can run the server on other port by defining custom port using the following command
rails s -p 3001
2. Or you can kill all the running ruby process by running following command
killall -9 ruby
then run rails server
Type in:
man lsof
Then look for -w, -n, and -i
-i: internet stuff -n: makes it faster -w: toggles warnings
There are WAY more details on the man pages
For anyone stumbling across this question that is not on a Mac: assuming you know that your server is running on port 3000, you can do this in one shot by executing the following:
fuser -k 3000/tcp
But as Toby has mentioned, the implementation of fuser in Mac OS is rather primitive and this command will not work on mac.
Some times there is a chance where rails server not closed properly. You can find process used by rails
ps aux | grep rails
Output will be like
user 12609 9.8 0.5 66456 45480 pts/0 Sl+ 21:06 0:02 /home/user/.rvm/rubies/ruby-2.2.0-preview1/bin/ruby bin/rails s
Here process_id 12609 is used by your rails server.
You can kill it easily by command
kill -9 12609
If you are on windows machine follow these steps.
c:/project/
cd tmp
c:/project/tmp
cd pids
c:/project/tmp/pids
dir
There you will a file called server.pid
delete it.
c:/project/tmp/pid> del *.pid
Thats it.
EDIT: Please refer this
One line solution:
kill -9 $(ps aux | grep 'rails s' | awk {'print$2'}); rails s
To kill process on a specific port, you can try this
npx kill-port [port-number]
Source: Stackoverflow.com