2011-01-05 1 views
0

루비 NFC 판독기 스크립트를 작성하고 데몬 gem으로 데몬 처리했습니다. 스크립트는 한 번만 실행을 제외한 모든 것이 ...Ruby 데몬 스크립트는 한 번만 실행됩니다.

Daemon.rb

을 위대한 작품을
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 => :normal, 
    :dir => File.join(pwd, 'tmp/pids'), # directory where pid file will be stored 
    :backtrace => true, 
    :monitor => true, 
    :log_output => true 
) do 
    exec "ruby #{file}" 
end 

touchatag.rb

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 => {:uid => tag.uid}) 
end 

이 잘 작동하고 난에 tag.uid를 받고있어 내 애플 리케이션. 하지만 다른 RFID 태그를 스캔하면 스크립트가 다시 실행되지 않습니다 ...

"영원히"실행되는 스크립트를 조정하는 방법을 알고 데몬이 중지되면 중지합니까?

감사

난 내 daemon.rb 스크립트를 업데이트

UPDATE :

require 'rubygems' 
require 'daemons' 

options = { 
    :app_name => "touchatag_project_daemon", 
    :ARGV  => ['start', '-f', '--', 'param_for_myscript'], 
    :dir_mode => :script, 
    :dir  => 'tmp/pids', 
    :multiple => true, 
    :ontop  => true, 
    # :mode  => :exec, 
    :backtrace => true, 
    :monitor => true 
} 

Daemons.run(File.join(File.dirname(__FILE__), '/touchatag.rb'), options) 

하지만 그냥 한 번 실행 ... 나는 그에게 다른 제안을 얻을하지 않습니다?

답변

1

거의 확실하게 Daemon.run을 사용하고 싶습니다. run_proctouchtag.rb에서 Daemon.rb으로 코드를 이동하려는 경우 유용합니다.

http://daemons.rubyforge.org/classes/Daemons.html#M000004

+0

난 당신의 제안에 내 게시물을 업데이트하지만 여전히 한 번만 실행 ... –

+0

죄송합니다, 나는 당신이 아마 잠이나 뭔가와 (루프에 touchtag 코드를 포장 할 필요가 있음을 언급하는 것을 잊었다 그곳에). 데몬 예제가'sleep {sleep} '등과 같이'loop {...}'에서 항상 발생하는 것에 주목하십시오. – cam

+0

좋아요! 그것은 매력처럼 작동합니다! 당신의 도움을 주셔서 감사합니다! –