Linux/logrotate

logrotate
logrotate - rotates, compresses, and mails system logs

Installation: yum install logrotate vixie-cron crontab service crond restart

Configuration files are here: /etc/cron.daily/logrotate /etc/logrotate.conf /etc/logrotate.d

Last rotate status is kept here: /var/lib/logrotate.status

Kick off a rotate config: logrotate -v /etc/logrotate.d/httpd

copytruncate
"To avoid the reload, instead of moving the file, you can copy it and empty the old file. That way apache can keep writing to the same filehandle. You do this by adding the option "copytruncate" to the logrotate config file, like this:"

/apache/*log { copytruncate compress dateext rotate 365 size=+300M olddir /log/old/apache notifempty missingok }

References:
 * logrotate - How to avoid apache reload when rotating logs? - Unix & Linux Stack Exchange - http://unix.stackexchange.com/questions/47688/how-to-avoid-apache-reload-when-rotating-logs

CentOS HTTP Example
Suggested add: /var/log/httpd/*log { size 100M compress ...

ln -s /etc/cron.daily/logrotate /etc/cron.hourly/logrotate

/etc/logrotate.d/httpd /var/log/httpd/*log { missingok notifempty sharedscripts delaycompress postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript }

/etc/logrotate.conf weekly
 * 1) see "man logrotate" for details
 * 2) rotate log files weekly

rotate 4
 * 1) keep 4 weeks worth of backlogs

create
 * 1) create new (empty) log files after rotating old ones

dateext
 * 1) use date as a suffix of the rotated file


 * 1) uncomment this if you want your log files compressed
 * 2) compress

include /etc/logrotate.d
 * 1) RPM packages drop log rotation information into this directory

/var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 }
 * 1) no packages own wtmp and btmp -- we'll rotate them here

/var/log/btmp { missingok monthly create 0600 root utmp rotate 1 }


 * 1) system-specific logs may be also be configured here.

/etc/cron.daily/logrotate /usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1 EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0