Guest User

Untitled

a guest
May 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #
  2. # log rotatation
  3. #
  4. # script/runner & cron で実行する
  5.  
  6. SERVER_PID = configatron.server.pid
  7. ACCESS_LOG = configatron.server.access_log
  8. ACCESS_LOG_STRFTIME = configatron.server.access_log_strftime
  9. RAILS_LOG = configatron.server.rails_log
  10. RAILS_LOG_STRFTIME = configatron.server.rails_log_strftime
  11.  
  12. File.umask(0000)
  13.  
  14. pid = File.read(SERVER_PID).to_i rescue nil
  15.  
  16. def rotate(src, dst)
  17. if FileTest.exist?(src)
  18. if !FileTest.exist?(dst)
  19. File.rename(src, dst)
  20. end
  21. end
  22. end
  23.  
  24. rotate(ACCESS_LOG, 1.day.ago.strftime(ACCESS_LOG_STRFTIME))
  25. rotate(RAILS_LOG, 1.day.ago.strftime(RAILS_LOG_STRFTIME))
  26.  
  27. Process.kill(:USR1, pid) if pid
  28.  
  29. system("touch", "#{RAILS_ROOT}/tmp/restart.txt")
Add Comment
Please, Sign In to add comment