[MDEV-16772] mysql-server logrotate script does not flush logs Created: 2018-07-18  Updated: 2021-12-03  Resolved: 2021-12-03

Status: Closed
Project: MariaDB Server
Component/s: Platform Debian, Scripts & Clients
Affects Version/s: 10.3.8
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Jan Ingvoldstad Assignee: Otto Kekäläinen
Resolution: Duplicate Votes: 0
Labels: contribution, logrotate, patch
Environment:

Debian Stretch


Attachments: File logrotate-mysql-server.patch    
Issue Links:
PartOf
is part of MDEV-22659 Create one single unified and optimal... Closed
Relates
relates to MDEV-16621 Fix logrotate script Closed

 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.



 Comments   
Comment by Elena Stepanova [ 2018-07-18 ]

Thank you for the report and the patch.

Comment by Otto Kekäläinen [ 2021-04-04 ]

Superseded by https://github.com/MariaDB/server/pull/1556 and MDEV-22659.

Comment by Otto Kekäläinen [ 2021-12-03 ]

This will be fixed via MDEV-22659

Generated at Thu Feb 08 08:31:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.