Bad file descriptor in Ruby Daemons

Using Ruby v1.8.7 and Daemons v1.1.8 on Mac OS X Lion, I am trying to write a consumption process and run it as 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 produces a long trace that looks 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'm not sure what causes this problem? All directory names, log file name are valid. I can create an instance of MyConsumer with these configurations and can correctly # sign it from a standalone program / console.

+7
source share
2 answers

Based on my experiences with Ruby Daemons, I found that such errors indicate that the base unit (which is the daemon) contains errors. Fixing these errors also fixes this error.

+3
source

You have typos in your example that may cause an error. Check the spelling for MyConsumer, which you transfer s and n ...

consumer = MyCosnumer.new(config) 
0
source

All Articles