English 中文(简体)
Ruby 守护程序中的错误文件描述符
原标题:Bad File Descriptor in Ruby Daemons
  • 时间:2012-05-28 14:07:41
  •  标签:
  • ruby
  • daemons

使用Ruby v1.8.7 和 Mac OS X 狮子上的守护进程 v1.1.8,

# config[:name] =>  idx_my_delete_consumer 
# config[:daemon] => {:multiple => false,
#                    :backtrace => true, 
#                    :dir_mode => :normal, 
#                    :log_dir =>  /Users/pprakash/consumer.log ,
#                    :monitor => true,
#                    :dir =>  /Users/pprakash/pids }

 Daemons.run_proc(config[:name], config[:daemon]) do
    consumer = MyConsumer.new(config)  
    consumer.subscribe
  end

然而,它并没有开始,反而抛下了长长的回溯,这就像这样:

E, [2012-05-28T19:34:16.199770 #29357] ERROR -- : Bad file descriptor (Errno::EBADF)
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:134:in `for_fd 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:134:in `close_io 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:134:in `initialize 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:134:in `new 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:134:in `close_io 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/daemonize.rb:75:in `call_as_daemon 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:258:in `start_proc 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:295:in `start 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:51:in `watch 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:51:in `fork 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:51:in `watch 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:45:in `each 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:45:in `watch 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:44:in `loop 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:44:in `watch 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:84:in `start_with_pidfile 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:64:in `fork 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:64:in `start_with_pidfile 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/monitor.rb:111:in `start 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/application_group.rb:149:in `create_monitor 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:284:in `start 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/controller.rb:70:in `run 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:197:in `run_proc 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `call 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `catch_exceptions 
/opt/local/lib/ruby/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:196:in `run_proc 
users/delete_consumer.rb:40

我不知道是什么原因引发了这个问题? 目录名、 日志文件名都是有效的 。 我可以用这些配置来创建 MyConsumer 实例, 并且能够从独立的程序/ concole 中正确执行它的# sublication 。

最佳回答

根据我对 Ruby 守护进程的经验, 我发现这些错误表明底块( 已启动) 包含错误。 修正这些错误也会修正这个错误 。

问题回答

您的示例中确实有可能导致错误的打字。 请检查 MyConsummer 的拼写, 您将 S 和 n 移植到...

consumer = MyCosnumer.new(config) 




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签