I want to create a daemon of a ruby program on Linux.
I also want the daemon to be interactive-I want to be able to send input to the daemon through a file/pipe/the simplest method and receive output to a file.
How do I go about doing this?
I've looked into the module daemons (http://daemons.rubyforge.org/), threads and the method popen3 but I'm having a hard time getting them to do the above.
ANSWER: Mladen's method:
I have the controller that creates the daemon: (you'll need the daemons module gem)
require 'rubygems'
require 'daemons'
Daemons.run('/myDaemon.rb', {:app_name => "o", :dir_mode => :normal, :dir => '', :log_output => true, :multiple => true })
Here's myDaemon.rb:
puts `pwd`
File.open('my_pipe', 'r+') do |f|
loop do
line = f.gets
puts "Got: #{line}"
end
end
Steps: Both files are in my root directory \. The Daemons.run creates the daemon in \.
Create a named pipe, mkfifo ./my_pipe.
ruby controller.rb start
cat > my_pipe
type text
ctrl-c to stop input
cat o.output to see your output