How to stop a Daemon Server in Rails?

Viewed 55295

I am running my rails application using the following

  $script/server -d webrick 

on my Ubuntu system , above command run the webrick server in background . I could kill the process using kill command

  $kill pid

Does rails provide any command to stop the background running daemon server ?

like the one provided by rails to start the server , Thanks .

EDIT When it is appropriate to start the daemon server ? Any real time scenario will help Thanks

15 Answers

if it can be useful, on linux you can find which process is using a port (in this case 3000) you can use:

lsof -i :3000

it'll return the pid too

Like Ryan said:

the pid you want is in tmp/pids/

probably server.pid is the file you want.

You should be able to run kill -9 $(cat tmp/pids/server.pid) to bring down a daemonized server.

The only proper way to kill the Ruby on Rails default server (which is WEBrick) is:

kill -INT $(cat tmp/pids/server.pid)

If you are running Mongrel, this is sufficient:

kill $(cat tmp/pids/server.pid)

Use kill -9 if your daemon hung. Remember the implications of kill -9 - if the data kept in Active Record caches weren't flushed to disk, you will lose your data. (As I recently did)

i don't think it does if you use -d. I'd just kill the process.

In the future, just open up another terminal window instead and use the command without -d, it provides some really useful debugging output.

If this is production, use something like passenger or thin, so that they're easy to stop the processes or restart the servers

You can start your server in the background by adding -d to your command. For instance:

puma -d

To stop it, just kill whatever process is running on port 3000:

kill $(cat tmp/pids/server.pid)
Related