0

I've been having the same problem for a couple of weeks now. I have the following /etc/logrotate.d/mariadb file configuration:

/var/log/mariadb/*.log {
        create 600 mysql mysql
        notifempty
        weekly
        rotate 12
        missingok
        delaycompress
    postrotate
        # just if mariadbd is really running
        if test -x /usr/bin/mysqladmin && \
           /usr/bin/mysqladmin ping &>/dev/null
        then
           env HOME=/root/ /usr/bin/mysqladmin --local flush-error-log \
              flush-engine-log flush-general-log flush-slow-log
        fi
    endscript
}

I also made the /root/.my.cnf file with permission 400 and contents:

[mysqladmin]
password = <secret>
user= root

It rotates the log just to a new log file but when I check the new logs no errors are logged and I had to flush the logs manually every week. And if I run sudo logrotate /etc/logrotate.d/mariadb the logs rotate just fine and new logs can be seen on the new log files. But if I let cron handle it weekly, the problem occurs.

Any idea on how to fix this issue? Thanks

5
  • If you need env HOME for the mysqladmin flush* commands you'd also need it on the mysqladmin ping. Your shell may have this already set. Maybe cron/logrotate doesn't. Its also possible that a global logrotate doesn't include the selinux permission to access /root/.my.cnf. Try putting credentials in non-globally readable /etc/my.cnf.d/mysqladmin.cnf file.
    – danblack
    Oct 19, 2021 at 1:45
  • Will give this one a try, I just also noticed that if I set it too weekly then the problem would persist, but if I set it to daily then no problem occurs.
    – Glen G
    Oct 19, 2021 at 6:37
  • see this recent answer, its has the same effect that the compressed files are empty. So its purely that your .my.cnf isn't read. This is honestly one reason that unix_socket auth permission on the root user are very useful, then its logs are rotatable and there's no password in a file that can leave access available. See also pr1556 (that I need to review again).
    – danblack
    Oct 19, 2021 at 10:10
  • Please provide ls -l before and after the rotate script runs.
    – Rick James
    Oct 19, 2021 at 17:42
  • -rw-------. 1 mysql mysql 619980 Oct 20 08:23 mariadb-err.log -rw-------. 1 mysql mysql 3357147 Oct 19 07:12 mariadb-err.log-20211017 After running sudo logrotate /etc/logrotate.d/mariadb I get -rw-------. 1 mysql mysql 79 Oct 20 08:24 mariadb-err.log -rw-------. 1 mysql mysql 619980 Oct 20 08:23 mariadb-err.log.1 -rw-------. 1 mysql mysql 3357147 Oct 19 07:12 mariadb-err.log-20211017
    – Glen G
    Oct 20, 2021 at 0:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.