Lighttpd log file rotation with logrotate

Posted on January 5, 2014 at 11:47 am

Open and edit the file located here:

/etc/logrotate.d/lighttpd

You should see something like this:

/var/log/lighttpd/*.log {
        daily
        missingok
        copytruncate
        rotate 12
        compress
	delaycompress
        dateformat -%Y-%m-%d
        dateext
        notifempty
        sharedscripts
        postrotate
             if [ -x /usr/sbin/invoke-rc.d ]; then \
                invoke-rc.d lighttpd reopen-logs > /dev/null 2>&1; \
             else \
                /etc/init.d/lighttpd reopen-logs > /dev/null 2>&1; \
             fi; \
        endscript
}

To rotate log files of other vHosts, see this example:

/var/log/lighttpd/*.log 
/var/www/host1.com/logs/*.log 
/var/www/host2.com/logs/*.log 
/var/www/host3.com/logs/*.log 
{
        daily
        missingok
        copytruncate
        rotate 12
        compress
	delaycompress
        dateformat -%Y-%m-%d
        dateext
        notifempty
        sharedscripts
        postrotate
             if [ -x /usr/sbin/invoke-rc.d ]; then \
                invoke-rc.d lighttpd reopen-logs > /dev/null 2>&1; \
             else \
                /etc/init.d/lighttpd reopen-logs > /dev/null 2>&1; \
             fi; \
        endscript
}

To make sure logrotate will never delete the old log files, use this example:

/var/log/lighttpd/*.log 
/var/www/host1.com/logs/*.log 
/var/www/host2.com/logs/*.log 
/var/www/host3.com/logs/*.log 
{
        daily
        missingok
        copytruncate
        rotate 365000
        compress
	delaycompress
        dateformat -%Y-%m-%d
        dateext
        notifempty
        sharedscripts
        postrotate
             if [ -x /usr/sbin/invoke-rc.d ]; then \
                invoke-rc.d lighttpd reopen-logs > /dev/null 2>&1; \
             else \
                /etc/init.d/lighttpd reopen-logs > /dev/null 2>&1; \
             fi; \
        endscript
}

You can see that the field “rotate” has changed to:

rotate 365000

It means logrotate will keep logs for 100+ years.

Updated on January 7, 2014 at 12:20 pm

Other Posts

Updated Posts