You are here: Home / Documentation / How To's / How to use logrotate

How to use logrotate

by nguyen — published Nov 13, 2009 12:10 AM, last modified Aug 16, 2016 10:50 AM
The logrotate Unix utility lets you control how large log files get, how long to retain them, etc. If you don't use something like logrotate, your event.log, instance.log, Z2.log files can get stupendously large. Not only do large log files take up lots of space, they also are harder to view and search through. This describes how to use logrotate in a ZEO server / ZEO client deployment of Plone.

On app.oie.uwosh.edu, I created /opt/Plone-2.5.5/logrotate-client1.conf

which contains

/opt/Plone-2.5.5/zeocluster/client1/log/*.log {
       compress
       daily
       olddir old
       rotate 10000
}


There is an equivalent /opt/Plone-2.5.5/logrotate-client2.conf

I decided to create a separate conf file per ZEO client since I can shut down only one ZEO client at a time, and it is only while a client is stopped that it is really safe to use logrotate on its log files (there is an option for logrotate that attempts to copy log files but it can lose some data).

In the script /root/bin/restart-plone-2.5.5-zeo-clients.sh I added a call to logrotate in between the client stop and start lines, for each client.  For example, here is what happens for ZEO client 2:

echo "RESTARTING ZOPE CLIENT 2"
/opt/Plone-2.5.5/zeocluster/client2/bin/zopectl stop
/usr/sbin/logrotate /opt/Plone-2.5.5/logrotate-client2.conf
/opt/Plone-2.5.5/zeocluster/client2/bin/zopectl start


When I invoke the restart script manually, logrotate works (it copies event.log and Z2.log into the "old" subdirectory and compresses them).

I also added the restart script to the crontab every Sunday, figuring that we should restart this Zope anyway at least weekly.

Probably with the settings and crontab as above we will retain 10,000 weekly log sets.  :-)

Warning re: buildout

If you use buildout, be careful not to put the logrotate-client*.conf files in the parts/client* directories because the next time you run bin/buildout it will clobber them!

I moved the logrotate-client*.conf files up into the /opt/Plone-whatever/zeocluster directory and changed the restart*.sh scripts to look for them in the new location.

 

Navigation