title: Ruby daemon script only runs once
body: <p>I've written a ruby NFC reader script and daemonised it with the daemons gem. It all works great except the script only runs once...</p>
  
  <p>Daemon.rb</p>
  
  <pre><code>require 'rubygems'
  require 'daemons'
  
  pwd  = File.dirname(File.expand_path(__FILE__))
  file = pwd + '/touchatag.rb'
  
  Daemons.run_proc(
    'touchatag_project_daemon', # name of daemon
    :dir_mode =&gt; :normal,
    :dir =&gt; File.join(pwd, 'tmp/pids'), # directory where pid file will be stored
    :backtrace =&gt; true,
    :monitor =&gt; true,
    :log_output =&gt; true
  ) do
    exec "ruby #{file}"
  end
  </code></pre>
  
  <p>touchatag.rb</p>
  
  <pre><code>quire 'rubygems'
  require 'nfc'
  require 'httparty'
  
  class TagAssociator
    include HTTParty
    base_uri 'localhost:3000'
  end
  
  NFC.instance.find do |tag|
    puts "Processing tag..."
    TagAssociator.post('/answers/answer', :query =&gt; {:uid =&gt; tag.uid})
  end
  </code></pre>
  
  <p>This works great and i'm receiving the tag.uid in my app. But when i scan another RFID tag the script wont run again...</p>
  
  <p>Does anyone know how to adjust the script that it runs "forever" and stops when the daemon is stopped?</p>
  
  <p>Thanks</p>
  
  <p>UPDATE</p>
  
  <p>i updated my daemon.rb script:</p>
  
  <pre><code>require 'rubygems'
  require 'daemons'
  
  options = {
    :app_name   =&gt; "touchatag_project_daemon",
    :ARGV       =&gt; ['start', '-f', '--', 'param_for_myscript'],
    :dir_mode   =&gt; :script,
    :dir        =&gt; 'tmp/pids',
    :multiple   =&gt; true,
    :ontop      =&gt; true,
    # :mode       =&gt; :exec,
    :backtrace  =&gt; true,
    :monitor    =&gt; true
  }
  
  Daemons.run(File.join(File.dirname(__FILE__), '/touchatag.rb'), options)
  </code></pre>
  
  <p>But it just runs once... i don't get it any other suggestions?</p>