服务器处理请求后,无法使用control-Z挂起webrick

时间:2014-10-28 22:39:19

标签: ruby-on-rails ruby-on-rails-4 signals webrick

在开发Rails 4.1.6项目时,我可以使用以下命令启动Webrick服务器:

rails s

在服务器处理任何请求之前,我可以:

  • 使用control-C
  • 停止它
  • 使用control-Z
  • 暂停它

服务器处理完一个请求后,我仍然可以用control-C来阻止它,但我不能再用control-Z暂停它。键入control-Z echoes" ^ Z"到终端,但服务器继续运行,并将处理它收到的任何请求。

为什么在服务器处理完请求后,control-Z无法暂停服务器?

详细

启动服务器:

$ rails s
Warning: NLS_LANG is not set. fallback to US7ASCII.
=> Booting WEBrick
=> Rails 4.1.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-10-28 15:16:09] INFO  WEBrick 1.3.1
[2014-10-28 15:16:09] INFO  ruby 2.1.2 (2014-05-08) [i686-linux]
[2014-10-28 15:16:09] INFO  WEBrick::HTTPServer#start: pid=29538 port=3000

服务器处理任何请求之前的Control-Z:

$ rails s
Warning: NLS_LANG is not set. fallback to US7ASCII.
=> Booting WEBrick
=> Rails 4.1.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
^Z
[1]+  Stopped                 rails s

处理请求:

Started GET "/" for 127.0.0.1 at 2014-10-28 15:18:24 -0700
  ActiveRecord::SchemaMigration Load (4.2ms)  SELECT "SCHEMA_MIGRATIONS".* FROM "SCHEMA_MIGRATIONS"
   (69.1ms)  SELECT column_name AS name, data_type AS sql_type, data_default, nullable, virtual_column, hidden_column, data_type_owner AS sql_type_owner, DECODE(data_type, 'NUMBER', data_precision, 'FLOAT', data_precision, 'VARCHAR2', DECODE(char_used, 'C', char_length, data_length), 'RAW', DECODE(char_used, 'C', char_length, data_length), 'CHAR', DECODE(char_used, 'C', char_length, data_length), NULL) AS limit, DECODE(data_type, 'NUMBER', data_scale, NULL) AS scale FROM all_tab_cols WHERE owner = 'DOCUMENT_DIRECTOR_DEVELOPMENT' AND table_name = 'SCHEMA_MIGRATIONS' AND hidden_column = 'NO' ORDER BY column_id
Processing by IndexController#index as JSON
  Rendered index/index.json.jbuilder (3.1ms)
Completed 200 OK in 10ms (Views: 9.9ms | ActiveRecord: 0.0ms)

处理请求后的Control-Z,多次按下因为我指的是业务:

^Z^Z^Z^Z^Z^Z

的Gemfile:

source 'https://rubygems.org'
source 'http://gems:9292'

gem 'activerecord-oracle_enhanced-adapter',
  git: 'https://github.com/wconrad/oracle-enhanced.git',
  branch: 'better-system-password-entry'
gem 'apipie-rails'
gem 'capistrano-rails', group: :development
gem 'capistrano-rvm'
gem 'cucumber-rails', :require => false, group: [:test]
gem 'cute_print'
gem 'database_cleaner', group: [:development, :test]
gem 'factory_girl_rails', group: [:development, :test]
gem 'jbuilder'
gem 'jsonpath', group: :test
gem 'maruku'
gem 'newrelic_rpm'
gem 'opacs_billing'
gem 'opacs_db'
gem 'rails'
gem 'rails-erd', group: :development
gem 'retryable'
gem 'rspec-rails', group: [:development, :test]
gem 'ruby-oci8'
gem 'sass-rails'
gem 'sdoc', group: :doc
gem 'simplecov', require: false, group: :test
gem 'spring', group: :development
gem 'versionist'
gem 'yard'

版本:

  • MRI 2.1.2
  • Rails 4.1.6
  • bash 4.2.37
  • Debian GNU / Linux" wheezy"

1 个答案:

答案 0 :(得分:2)

在您在问题评论部分写的评论中,您说:

  

用例是:control-Z,然后" bg"在后台恢复服务器,然后尾随日志。

我认为问题在于将服务器放在后台而不是前台(使用命令fg)。如果你把服务器放在后台,控制台就不能再停止它,直到你把它放在前台,所以CTRL-Z不能工作。所以,我会尝试以下序列:

  1. rails s
  2. CONTROL-Z(程序暂停)
  3. fg(程序已恢复)
  4. CONTROL-Z(程序是否再次停止?)
  5. 如果您想继续将服务器放在后台,那么您可以向其发送STOP信号,而不是输入CONTROL-Z,而是使用kill发送信号:

    kill -STOP <SERVER_PID> 
    

    kill -s STOP <SERVER_PID>
    

    (取决于您的系统)。

    要恢复此过程:

    kill -CONT <SERVER_PID>
    

    kill -s CONT <SERVER_PID>