8

When I try to start a server via rails s, I get the following error message:

C:\Users\Frankie\Documents\stocktracker>rails s
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
A server is already running. Check C:/Users/Frankie/Documents/stocktracker/tmp/p
ids/server.pid.
Exiting

The number listed in server.pid is 8436.

How do I manually kill this process? How can I easily kill all webrick servers currently running?

Daniel Evans
  • 6,788
  • 1
  • 31
  • 39
fbonetti
  • 6,652
  • 3
  • 34
  • 32
  • I believe that message is only indicating that another process is bound to port 3000. Not necessarily another WEBrick process. I think this utility will help you find the tcp port processes are listening on: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx (it's been a while since I've worked on windows) – Brian Jan 09 '13 at 19:15
  • kill -INT $(cat tmp/pids/server.pid) [see here][1] [1]: http://stackoverflow.com/questions/15088163/cant-stop-rails-server#answer-15088254 – Montells Mar 19 '14 at 15:57

5 Answers5

12

You can use the taskkill utility.

taskkill /PID 8436
Daniel Evans
  • 6,788
  • 1
  • 31
  • 39
1

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.

Chase
  • 2,748
  • 2
  • 23
  • 32
0

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.

Bob Calco
  • 11
  • 1
0

For Linux/Ubuntu Users, ubuntu has kill command. While running webrick server, in project directory within location APP_DIR/tmp/pids/server.pid there will be all Process Ids saved.
You just need to open the file, you will find the Process Id of currently running server. Now you can use the following command to kill the process

$ kill [pid] # Example kill 8123
Shiva
  • 11,485
  • 2
  • 67
  • 84
  • for further info : https://cbabhusal.wordpress.com/2015/02/03/forcefully-kill-webrick-instance-in-ubuntu-and-windows/ – Shiva Feb 03 '15 at 12:56
-2

Follow these steps:

1.Find 'rails s' process id by: ps -aux | grep rails

2.Use kill command with -9 option as: kill -p [PID]

you will not be disappointed!!

Jaswinder
  • 1,455
  • 14
  • 27