1. Add rotation script to logrotate
sudo vi /etc/logrotate.conf
add
# system-specific logs may be also be configured here.
/usr/local/Zope/Sites/SiteName/log/Z2.log {
rotate 5
weekly
compress
size=100k
sharedscripts
postrotate
#close and re-open all Zope log files (z2.log, event.log) The common idiom after rotating Zope log files
/bin/kill -s SIGUSR2 `cat /usr/local/Zope/Sites/SiteName/var/Z2.pid`
endscript
}
/usr/local/Zope/Sites/SiteName/log/event.log {
rotate 5
weekly
compress
size=100k
}
2. Test log rotation
Do a test run of the rotation without actually rotating anything:
/usr/sbin/logrotate -d /etc/logrotate.conf
if the test run completes without any erros, force a rotation:
/usr/sbin/logrotate -f /etc/logrotate.conf
3. Automate with crontab
On RedHat, crontab may be set up with runparts e.g.
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthlyIn this case, place a script in the directory where it should run regularly. I’m going to rotate weekly for now, so I’m placing a script in /etc/cron.weekly and naming it zope.cron (you can name it whatever you want. Any script in this directory will run weekely
sudo vi /etc/cron.weekly/zope.cron
#rotate Z2.log and event.log in SiteName
0 01 * * * root /usr/sbin/logrotate /etc/logrotate.conf > /dev/null2>&1