How do I kill a rails webrick server? How do I kill a rails webrick server? windows windows

How do I kill a rails webrick server?


You can use the taskkill utility.

taskkill /PID 8436


If you are using iTerm2 on OSX you can open Toolbelt => ShowToolbelt, select ruby pid 8436 then click send signal to kill it. Occasionally task kill doesn't work for me.

Also, you can ps -aux | grep rails to find the pid. and then kill like the other answers recommend.


The following task definition works for me (put it in a *.rake file in your lib\tasks folder):

namespace :server do  # ---------------------------------------------------------------------------  desc "Clear the previous server instance clutter."  task :cleanup => :environment do          pidfile = 'tmp/pids/server.pid'    if File.exists? pidfile      pid = File.read(pidfile).to_i      if RbConfig::CONFIG['host_os'] =~ /mswin32/        sh "taskkill /f /pid #{pid}"        sh "del tmp\\pids\\server.pid"      else        sh "kill #{pid}"        sh "rm #{pidfile}"      end      puts "All cleaned up. Yay!"    else      puts "Already clean. Whew!"    end  end  # ---------------------------------------------------------------------------  desc "Start an instance of the server cleanly."  task :startup => :cleanup do    sh "rails server"  end  # ---------------------------------------------------------------------------end

Now just run

rake server:startup

It cleans up any leftover processes and pid files on Windoze before trying to run the rails server again.