Ruby守护进程中的错误文件描述符
在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。
根据我对Ruby守护进程的经验,我发现这样的错误表明底层块(被守护进程)包含错误。 修复这些错误也会修复此错误。
您的示例中有错别字可能导致错误。 检查MyConsumer的拼写,您将s和n调换为...
consumer = MyCosnumer.new(config)
链接地址: http://www.djcxy.com/p/10783.html
上一篇: Bad File Descriptor in Ruby Daemons
下一篇: ignore certain files in all folders using a single .gitignore file