Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#
# 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