简体   繁体   English

Ruby守护程序中的错误文件描述符

[英]Bad File Descriptor in Ruby Daemons

Using Ruby v1.8.7 and Daemons v1.1.8 on Mac OS X Lion, I am attempting to write a consumer process and get it run as a dameon: 在Mac OS X Lion上使用Ruby v1.8.7和Daemons v1.1.8,我试图编写一个消费者进程并让它作为dameon运行:

# 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

However, it does not start and instead throws a long traceback, which goes something like this: 但是,它没有启动,而是抛出一个很长的回溯,这是这样的:

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

I am not sure what is causing this issue? 我不确定是什么导致了这个问题? The directory name, log file name are all valid. 目录名,日志文件名都有效。 I am able to create an instance of MyConsumer with these config and able to execute its #subscribe properly from a standalone program/console. 我能够使用这些配置创建一个MyConsumer实例,并能够从独立程序/控制台正确执行其#subscribe。

Based on my experiences with Ruby Daemons, I found that such errors indicate that the underlying block (which is daemonized) contains errors. 根据我对Ruby Daemons的经验,我发现这些错误表明底层块(守护进程)包含错误。 Fixing those errors fixes this error as well. 修复这些错误也可以修复此错误。

You do have typos in your example that may be causing the error. 您的示例中确实存在可能导致错误的拼写错误。 Check the spelling for MyConsumer, which you transposed the s and n... 检查MyConsumer的拼写,你转换了s和n ...

consumer = MyCosnumer.new(config) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM