1

How can I make log rotation on my production env for rails version 3.2.8?

I have taking a look to Ruby on Rails production log rotation, but is for old rails version.

I use nginx + unicorn

Where can I find more info about this?

Thank you very much!

Community
  • 1
  • 1
hyperrjas
  • 10,666
  • 25
  • 99
  • 198

1 Answers1

0

This shell script worked for me. I set up cron to execute this script every night, just before midnight. You'll need to adjust the directories to your own application. Note that the directory references are relative to my application's root directory. The "kill" command tells the master unicorn process to reload, which automatically creates a new production.log and unicorn.log file.

#!/bin/bash
# Rotates unicorn.log and production.log files located
# in the <application_root>/log folder.
# Deletes compressed logs older than 60 days.
NOW=`date +%Y%m%d_%H%M%S`
cd /home/deployer/apps/stations/current
mv log/production.log log/production_$NOW.log
mv log/unicorn.log log/unicorn_$NOW.log
kill -s USR1 `cat tmp/pids/unicorn.pid`
sleep 1
gzip log/production_$NOW.log
gzip log/unicorn_$NOW.log
find log/ -type f -mtime +60 -name "*.gz" -delete
Doug Hall
  • 156
  • 1
  • 6