I am trying to run multiple instances of the same code/script using the Daemons gem. I've been playing around with it in an IRB session and can't seem to get the functionality I'm looking for. I want to run the same script multiple times keeping track of the PID so that I can manually start and stop processes. More specifically, I have a rails model whose instance will control a single process and so I will need to start and stop it using something like
mydaemon = MyDaemon.create
mydaemon.start # starts the process
mydaemon.stop # stops the process
However, in order to achieve something like this I wanted to store the PIDs for the process in active record. When I run the following code in IRB:
require 'rubygems' # if you use RubyGems
require 'daemons'
task1 = Daemons.call(:multiple => true) do
loop {
File.open("/tmp/daemon_test.log", "w") {|f| f.write(Time.now.to_s + "\n")}
sleep 5
}
end
the task automatically starts (without ever calling start on task1), and instead of returning the pid, it returns the Daemons::Application object associated with task1. I only have access to the pid when I start a second instance of task1 i.e.:
task1.start
=> 574 # PID of process but now I have 2 proc's running, one of which I don't know the PID of
Am I using Daemons wrong? or is there no way to get the PID of the very first process that starts automatically when calling Daemons.call?
Thanks, Tomek