Skip to content

Instantly share code, notes, and snippets.

@riffraff
Created March 16, 2015 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riffraff/419a556188efaa994627 to your computer and use it in GitHub Desktop.
Save riffraff/419a556188efaa994627 to your computer and use it in GitHub Desktop.
#!/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