I am running my rails application using the following
$script/server -d webrick
on my Ubuntu system , above command run the webrick s
pguardiario beat me to it, though his implementation is a bit dangerous since it uses SIGKILL
instead of the (recommended) SIGINT
. Here's a rake task I tend to import into my development projects:
lib/tasks/stopserver.rake
desc 'stop server'
task :stopserver do
pid_file = 'tmp/pids/server.pid'
if File.file?(pid_file)
print "Shutting down WEBrick\n"
pid = File.read(pid_file).to_i
Process.kill "INT", pid
end
File.file?(pid_file) && File.delete(pid_file)
end
This issues an interrupt to the server if and only if the pidfile exists. It doesn't throw unsightly errors if the server isn't running, and it notifies you if it's actually shutting the server down.
If you notice that the server doesn't want to shut down using this task, add the following line after the Process.kill "INT"
line, and try to upgrade to a kernel that has this bug fixed.
Process.kill "CONT", pid
(Hat tip: jackr)
if kill process not works, then delete file server.pid from MyRailsApp/tmp/pids/
A Ruby ticket, http://bugs.ruby-lang.org/issues/4777, suggests it's a kernel (Linux) bug. They give a work around (essentially equivalent to the Ctrl-C/Ctrl-Z one), for use if you've demonized the server:
cat tmp/pids/server.pid
cat tmp/pids/server.pid
This seems to cause the original INT signal to be processed, possibly allowing data flush and so on.