English 中文(简体)
Ruby Daemons Gem
原标题:

I installed the ruby gem Daemons. To make sure it was working I created a script that would print to a file every 5 seconds. I then created another file to run the script using the trivial example they give you in the readme located at http://daemons.rubyforge.org/ . I require both rubygems and daemons. Then I type ruby mycontrol.rb start . The example they use has some type of message saying (myserver.rb is now running in the background) , I don t see that, but I don t get any errors. If I do a ps -u myusername I see that the filed to be daemonized is listed in the processes, but doesn t appear to be running as nothing is getting written to the file.

Here is my source:

# this is mycontrol.rb

require  rubygems 
require  daemons 

Daemons.run(daemon.rb)

and...

# this is daemon.rb

loop do 
 open( file.out ,  w ) do |f|
  f.puts  hello everybody 
 end
 sleep(3)
end

Does anything I m doing jump out at you as being wrong?

Thanks, Tony

最佳回答

I ve tried your example and it works for me (Ruby 1.8.6 on Linux with Daemons version 1.0.10). However, you may be encountering the following issues:

  • I found that the daemonized process (daemon.rb) was being started with a current working directory of /. This was not the current directory when running mycontrol.rb or the directory that contained daemon.rb. Running as a non-root user meant that my process didn t have permission to write the file. I changed the filename to /tmp/file.out and the file was created with the expected content.

  • You are opening file.out in write-only ( w ) mode. This means that it will be truncated and rewritten every 3 seconds. If you open the file in append ( a ) mode you will see an additional hello everybody line written to the file every 3 seconds.

I don t see the is now running in the background messages either. I assume this is included in the documentation to illustrate what should have happened rather than to indicate the output.

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签