Skip to main content

Rsyslog stops logging after logrotate

·1 min

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 logrotate with logrotate -v --force /etc/logrotate.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.

Edit: After switching to Debian my postrotate is /usr/bin/systemctl kill -s HUP rsyslog.service