Linux - logrotate

http://www.thegeekstuff.com/2010/07/logrotate-examples/

The logrotate program is a log file manager. It is used to rotate log files. It may be used to rotate log files based on age of the file, or the size of the file, and is usually run automatically through cron. logrotate can also be used to compress log files, and to email users when log file is rotated.

/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}
/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

Notice the wild card character (*) in the configuration for httpd. It works because it is at the beginning. The following:

/var/log/httpd/apache* {
    missingok
    notifempty
    sharedscripts
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

also worked but had problem. It generate ton of log files (empty log files), because the wild card character is at the end, which matches apache_error.log, apache_error.log.1, apache_error.log.1.1. Every time logrotate is run, .1 is appended to existing files, a new file is created, and .2 is never created, which breaks logrotate filename convention, therefore log files is always added but never removed (never rotated).

So avoid using wild card if you can.

What is the default configuration file for logrotate?

/etc/logrotate.conf

Where are other configuration files are kept?

/etc/logrotate.d

What information is in the default configuration file?

Information in the default configuration file ( /etc/logrotate.conf ) are the default values. Information in other configuration files overrides these default values.

How are configuration files for logrotate organized?

Default values are kept in /etc/logrotate.conf. Configuration files for specific services are kept in /etc/logrotate.d. Settings specified in service-specific configuration file override default value specified in /etc/logrotate.conf

How to disable log rotation for any service?

Delete appropriate file from /etc/logrotate.d, or comment out its content.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License