Search code examples
rubysinatrarackwebrick

Unable to stop Webrick launched by "rackup"


I'm developing a Sinatra application and I'm using "rackup" to start Webrick. What should I do to stop it? Now I'm using Ctrl+Z and it seems like it stops. However when I try to start it again it will say that the port is already bound.

I tried it with many ports and each time it started, stopped and then said it was in use when I restarted it again.

How do I solve it?


Solution

  • Ctrl+Z will just "pause" the process, not terminate / kill it.

    To truly kill it, find it in the process table and do kill -9 [PID]

    like:

    ps auxwww | grep ruby
    slivu  16244   0.0  0.5  2551140  61220 s020  R+    1:18AM   0:10.70 ruby app.rb
    

    the second column(16244) is the PID.

    The other way is to "catch" the INT signal with Ruby and exit the app explicitly.

    in your app:

    Signal.trap 'INT' do
        Process.kill 9, Process.pid
    end