Maintenance of Rails Programs
original at: http://tech.rufy.com/entry/15
1 2 pid_file = '/tmp/running.pid' 3 begin 4 File.stat pid_file 5 rescue 6 f = File.new pid_file, 'w' 7 f < < fork { 8 loop { 9 # do lots of maintenance 10 sleep 15*60 11 } 12 } 13 f.close 14 end
Finally, if your maintenance code needs to be changed, a couple simple commands can restart the new maintenance code:
1 2 kill `cat /tmp/running.pid` 3 rm /tmp/running.pid