pguardiario defeated me, although its implementation is a bit dangerous because SIGKILL used instead of SIGKILL . Here is the rake task that I am trying 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 causes an interrupt for the server if and only if the pidfile exists. It does not throw unsightly errors if the server is not running, and it notifies you if it actually closes the server.
If you notice that the server does not want to close this task, add the following line after the line Process.kill "INT" and try switching to the kernel with a fixed error.
Process.kill "CONT", pid
(hat tip: jackr )
Justin α
ααααα Jun 13 2018-12-12T00: 00Z
source share