How do I kill a rails webrick server?
Asked Answered
P

5

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?

Prolocutor answered 9/1, 2013 at 18:46 Comment(2)
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: technet.microsoft.com/en-us/sysinternals/bb896653.aspx (it's been a while since I've worked on windows)Fisch
kill -INT $(cat tmp/pids/server.pid) [see here][1] [1]: #15088663Mccarthy
K
12

You can use the taskkill utility.

taskkill /PID 8436
Knish answered 9/1, 2013 at 18:58 Comment(4)
I already tried that, but apparently the process didn't exist. ERROR: The process "8436" not found.Prolocutor
Then it is possible the process is already dead and it couldn't clean up its pid file. I would delete the pid file manually and try again.Knish
@effbott Where is the PID file at?Pembroke
@LearningROR ~/<YOUR APP FOLDER>/tmp/pidsProlocutor
P
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.

Pidgin answered 11/5, 2014 at 4:15 Comment(0)
I
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.

Inclusive answered 10/5, 2014 at 22:52 Comment(0)
A
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
Assured answered 3/2, 2015 at 12:47 Comment(1)
for further info : cbabhusal.wordpress.com/2015/02/03/…Assured
D
-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!!

Duel answered 19/8, 2015 at 7:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.