Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

ruby on rails - Can't stop WEBrick 1.3.1 with ctrl-c on Ubuntu 11.04

I'm using RVM, Ruby 1.9.2, and Rails 3.0.7

A standard kill of the process from another terminal doesn't work, either, but kill -9 does, of course.

I found a similar question, CTRL+C to Webbrick server ignored, but it's unclear whether that question is describing the same underlying issue. Also, the resolution doesn't seem to apply, since I'm not using :git in my Gemfile.

update 1: (old now... see update 2, below, for the real scoop)

I managed to narrow the issue down to a single gem. If you source the following test script, you can see the issue, too (assuming you're on Ubuntu 11.04... there was no issue in 10.04)

rm -rf tmpkilltest

rvm 1.9.2
rvm --force gemset delete tmpkilltest
rvm gemset create tmpkilltest
rvm 1.9.2@tmpkilltest

gem install rails -v=3.0.7 --no-rdoc --no-ri
gem install sqlite3 -v=1.3.3 --no-rdoc --no-ri

rails new tmpkilltest

cd tmpkilltest

echo "gem 'barista', '1.0'" >> Gemfile

bundle

rails s

The fact that the issue is caused by Rails' interaction with a gem leads me to now believe that this question actually is related to CTRL+C to Webbrick server ignored, though the test case above shows that this one is clearly not caused by using :git for a gem.

update 2:

In update 1 I mentioned that I narrowed it down to a gem. When I went through that gem, I eventually found the real culprit. The gem was making a single system call. I've made a very minor modification to the test script where I no longer load the barista gem, but rather I simply append a single system call at the end of the application.rb. With that system call, ctrl-c doesn't work. Remove the system call and it does work.

rm -rf tmpkilltest

rvm 1.9.2
rvm --force gemset delete tmpkilltest
rvm gemset create tmpkilltest
rvm 1.9.2@tmpkilltest

gem install rails -v=3.0.7 --no-rdoc --no-ri
gem install sqlite3 -v=1.3.3 --no-rdoc --no-ri

rails new tmpkilltest

cd tmpkilltest

bundle

echo "`date`" >> config/application.rb

rails s

This could explain the seeming similarity between this question and CTRL+C to Webbrick server ignored. My hunch is that the gem they mention also makes a system call.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'd rather comment than add an answer for this, but not enough rep.

I have the same issue and found that resuming (with fg) after typing ctrl-c then pausing (with ctrl-z, as offered above) does the trick.

So the recipe is:

  1. ctrl-c (does nothing right away)
  2. ctrl-z (pauses WEBrick, goes back to shell)
  3. fg (resumes WEBrick, immediately follow through with SIGINT)

    lampadmin@lampadmin-DX4840:/var/www/rails/agences$ r s
    => Booting WEBrick
    => Rails 3.0.5 application starting in development on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    [2011-05-14 14:25:36] INFO  WEBrick 1.3.1
    [2011-05-14 14:25:36] INFO  ruby 1.9.2 (2011-02-18) [x86_64-linux]
    [2011-05-14 14:25:36] INFO  WEBrick::HTTPServer#start: pid=2585 port=3000
    

    ^C^Z (<-- ctrl-c, then ctrl-z)

    [1]+  Stopped                 rails s
    lampadmin@lampadmin-DX4840:/var/www/rails/agences$ fg
    rails s
    [2011-05-14 14:25:45] INFO  going to shutdown ...
    [2011-05-14 14:25:45] INFO  WEBrick::HTTPServer#start done.
    Exiting
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...