Hi All,
I've come across a scenario when I was using the systemu within a service and the service was not shutting down
properly.
The documentation says the service should be implemented as follows when trying to get the process id. (Note I have
changes the sleep timeout to 900)
looper = %q( ruby -e" loop{ STDERR.puts Time.now.to_i; sleep 1 } " )
status, stdout, stderr =
systemu looper do |cid|
sleep 900
Process.kill 9, cid
end
However I noticed when doing this even if the job completes succesfully if I shutdown the service it always fails.
Instead I used the following and the service now shuts down properly. Not too sure if this is a bug or may be helpful
in anyway but it solves a problem with the service we are using.
t1 = Thread.new {
status, stdout, stderr =
systemu @fetch_job.cmd_line do |cid|
@fetch_job.process_id = cid.to_s
@fetch_job.status = "Running"
@fetch_job.save
end
}
start = Time.now
while t1.alive? do
if Time.now - start > 900
logger.error "Killing thread. Timed out"
t1.kill!
@fetch_job.cmd_output = ""
@fetch_job.status = "Timed Out"
@fetch_job.save
break;
end
sleep 2
end
Cheers
Andrew |