I want to create a ruby program daemon on Linux.
I also want the daemon to be interactive - I want to be able to send input to the daemon via file / pipe / the easiest method and get output to the file.
How can I do it?
I looked at the module daemons (http://daemons.rubyforge.org/), streams, and the popen3 method, but it's not easy for me to get them to do this.
ANSWER: Mladen Method:
I have a controller that creates a demon: (you will need the pearl of the demon module)
require 'rubygems' require 'daemons' Daemons.run('/myDaemon.rb', {:app_name => "o", :dir_mode => :normal, :dir => '', :log_output => true, :multiple => true })
Here is 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 \. Daemons.run creates a daemon in \.
source share