How to safely kill rails WEBrick server running in daemon mode

Ruby on rails and the WEBrick Daemon are great for testing however there are times when you start a WEBrick server in daemon mode and later find you need to stop this without restarting the box. This can sometimes be troublesome, especially if you accidently kill a live server. In this tutorial I’ll go through ensuring you kill the correct process.

First we need to find the PID of the WEBrick Daemon in order to stop it, to do this we’ll find the PID that has port 3000 bound to it:

sudo netstat -lp | grep 3000

This should give an output like this: Note: if you started your WEBrick server under a different port just change the 3000 in this command to the port you used.

This output tell you that PID (in my instance) that’s running the WEBrick server is 22673, this will be different for you server so please note down the PID (its the number before /ruby). Now we just need to kill this process to do this we use the following command (substitute [PID] for the PID you noted in the previous step):

sudo kill -9 [PID]

Now the WEBrick server will stop and you didn’t have to restart the machine.


, , , , , , , , , , , , ,

Comments are closed.