Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-16772

mysql-server logrotate script does not flush logs

    Details

      Description

      On Debian Stretch with MariaDB 10.3.8, provided via the official MariaDB debian package repo, logrotation always fails, leaving the mysqld process having "disappearing" logfiles.

      The problem was present in 10.2.x as well, as far as I can recall, and the logrotate script has the same issue in 10.0.x.

      The problem is caused by a failing assumption in the provided logrotate script. A patch with a hotfix for the issue is included.

      /etc/logrotate.d/mysql-server contains the following code:

              postrotate
                test -x /usr/bin/mysqladmin || exit 0
                if [ -f `my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"` ]; then
                  # If this fails, check debian.conf!
                  mysqladmin --defaults-file=/etc/mysql/debian.cnf --local flush-error-log \
                    flush-engine-log flush-general-log flush-slow-log
                fi
              endscript
      

      However, this fails, because the my_print_defaults-grep pipe produces two lines of output:

      root@testserver:~# my_print_defaults --mysqld | grep -oP "pid-file=\K[^$]+"
      /var/run/mysqld/mysqld.pid
      /var/run/mysqld/mysqld.pid
      

      This is due to my_print_defaults --mysqld printing every default twice, and thus the assumption that grep produces one line of output fails.

      Hotfix: add parameter "-m 1" to the grep statement to ensure a maximum of 1 matched line, so that the postrotate section reads as follows:

              postrotate
                test -x /usr/bin/mysqladmin || exit 0
                if [ -f `my_print_defaults --mysqld | grep -oP -m 1 "pid-file=\K[^$]+"` ]; then
                  # If this fails, check debian.conf!
                  mysqladmin --defaults-file=/etc/mysql/debian.cnf --local flush-error-log \
                    flush-engine-log flush-general-log flush-slow-log
                fi
              endscript
      

      A better long-term solution is described in MDEV-16621.

      The hotfix assumes that the first of any duplicate print-outs is the correct one.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cvicentiu Vicențiu Ciorbaru
                Reporter:
                frettled Jan Ingvoldstad
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: