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

时间:2012-05-28 14:07:41

标签: ruby daemons

在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

然而,它没有启动,而是抛出一个很长的追溯,这是这样的:

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实例,并能够从独立程序/控制台正确执行其#subscribe。

2 个答案:

答案 0 :(得分:3)

根据我对Ruby Daemons的经验,我发现这些错误表明底层块(守护进程)包含错误。修复这些错误也可以修复此错误。

答案 1 :(得分:0)

您的示例中确实存在可能导致错误的拼写错误。检查MyConsumer的拼写,你转换了s和n ...

consumer = MyCosnumer.new(config)