Skip to content

Instantly share code, notes, and snippets.

@riffraff
Created Mar 16, 2015
Embed
What would you like to do?
#!/usr/bin/env ruby
# vim: syntax=ruby
require 'timeout'
timeout = (ENV['TIMEOUT'] || 2*60*60).to_i
def log str
puts "run-forever: #{str}"
end
loop do
log "looping.."
pid = fork do
log "exec'ing #{ARGV.inspect}"
Process.exec(*ARGV)
end
begin
Timeout.timeout(timeout) do
Process.wait(pid)
end
rescue Timeout::Error
log "time passed, restarting"
Process.kill('INT', pid)
Process.wait(pid)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment