Categories
Debugging

Rsyslog stops logging after logrotate

Are you seeing an empty /var/log/haproxy.traffic.log file after logrotate does it’s business? Perhaps it’s your postrotate script!

Several tutorials on the web call “reload” in the logrotate postrotate script. For example the following is old and busted.

/var/log/haproxy.log {
    ...
    postrotate
        reload rsyslog >/dev/null 2>&1 || true
    endscript
}

On my CentOS systems I removed the error redirect and manually ran logroatate with logrotate -v --force /etc/logratate.d/haproxy. The output revealed that the reload command was no where to be found.

running postrotate script
logrotate_script: line 1: reload: command not found

Instead of reload use kill -HUP as follows. The man pages for rsyslogd state that HUP “lets rsyslogd perform close all open files.” Please do ensure that your pid exists at /run/rsyslogd.pid

/var/log/haproxy.log {
    ...
    postrotate
        /bin/kill -HUP `cat /run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

As far as I can tell reload was removed during the switch to systemd in CentOS 7. Although, I had a lot of trouble figuring out exactly what changes caused the initial script to be incorrect.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.