Skip to content

Instantly share code, notes, and snippets.

@willnet
Created July 13, 2010 11:09
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 willnet/473729 to your computer and use it in GitHub Desktop.
Save willnet/473729 to your computer and use it in GitHub Desktop.
#
# log rotatation
#
# script/runner & cron で実行する
SERVER_PID = configatron.server.pid
ACCESS_LOG = configatron.server.access_log
ACCESS_LOG_STRFTIME = configatron.server.access_log_strftime
RAILS_LOG = configatron.server.rails_log
RAILS_LOG_STRFTIME = configatron.server.rails_log_strftime
File.umask(0000)
pid = File.read(SERVER_PID).to_i rescue nil
def rotate(src, dst)
if FileTest.exist?(src)
if !FileTest.exist?(dst)
File.rename(src, dst)
end
end
end
rotate(ACCESS_LOG, 1.day.ago.strftime(ACCESS_LOG_STRFTIME))
rotate(RAILS_LOG, 1.day.ago.strftime(RAILS_LOG_STRFTIME))
Process.kill(:USR1, pid) if pid
system("touch", "#{RAILS_ROOT}/tmp/restart.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment