How to ensure a process is running in Ruby -


i call ffmpeg command in rails grep stream , push wowza apple device can see also, command this

thread.new   `/usr/local/bin/ffmpeg -re -i http://10.191.255.90:30080/#{user.phone} -vcodec libx264 -vpre ipod640 -g 15 -acodec libvo_aacenc -ar 8000 -ac 1 -f flv rtmp://127.0.0.1/live/#{user.phone}` end 

sometimes process killed because of break of network or other reasons, i'm wondering there way can monitor process stop can restart again

my current idea record pid of process, , let resque check whether process of given pid running every 60 sencods, has lot of such process wondering it's performance problem later.

is there better solution manage these process in ruby?

you can this:

thread.new   begin     process.wait process.spawn 'find /oeinfsroif'     raise unless $?.exitstatus == 0   rescue     retry   end end.join 

to manage number of attempts before failing:

thread.new   max_attempts = 10   attempts = 0   begin     process.wait process.spawn 'find /oeinfsroif'     raise unless $?.exitstatus == 0   rescue     attempts += 1     attempts < max_attempts ? retry : raise    end end.join 

output:

find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory find: `/oeinfsroif': no such file or directory rb:6:in `block in <main>': unhandled exception 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -