DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Maintenance Of Rails Programs

06.03.2005
| 1899 views |
  • submit to reddit
        This is a maintenance script, yanked from Lucas Carlson's blog.  Put this in your rails app to have a quick and dirty server maintenance cleanup app:

original at: http://tech.rufy.com/entry/15

pid_file = '/tmp/running.pid'
begin
  File.stat pid_file
rescue
  f = File.new pid_file, 'w'
  f < < fork {
    loop {
      # do lots of maintenance
      sleep 15*60
    }
  }
  f.close
end

Finally, if your maintenance code needs to be changed, a couple simple commands can restart the new maintenance code:

kill `cat /tmp/running.pid`
rm /tmp/running.pid