在 Mac OS X Lion 上使用 Ruby v1.8.7 和 Daemons 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]) 做 消费者 = MyConsumer.new(config) 消费者订阅 结尾
然而,它并没有启动,而是抛出了一个很长的回溯,如下所示:
E, [2012-05-28T19:34:16.199770 #29357] 错误 -- : 错误的文件描述符 (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' 用户/delete_consumer.rb:40
我不确定是什么导致了这个问题?目录名、日志文件名都有效。我能够使用这些配置创建 MyConsumer 的实例,并能够从独立程序/控制台正确执行其#subscribe。