#544013 mysql-server-5.1: logrotate script cannot handle stopped mysqld

Package:
mysql-server
Source:
mysql-8.0
Description:
MySQL database server and system database setup
Submitter:
Helmut Grohne
Date:
2025-08-22 19:15:03 UTC
Severity:
normal
#544013#5
Date:
2009-08-28 07:14:52 UTC
From:
To:
Hi,

I'm one of those users who are forced to install mysql-server as a
dependency, but really do not want to run it, especially not as a system
service. I therefore stopped mysql and removed all links in /etc/rc*.d/.
However the logrotate script seems to be unable to handle this case:

/etc/cron.daily/logrotate:
error: error running shared postrotate script for '/var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

I hope that you get the package properly split for akonadi soon, because
at the moment kdepim is a real pain.

Helmut

#544013#10
Date:
2010-02-02 15:07:59 UTC
From:
To:
Here's an alternative fix I'm using.  In /etc/logrotate.d/mysql-server,
change this line

                  if ps cax | grep -q mysqld; then

to this

                  if killall -q -s0 -umysql mysqld; then

That should cause the check to ignore any running mysqld processes
that aren't the system wide service.

David

#544013#15
Date:
2012-04-11 10:09:52 UTC
From:
To:
Hi,

more than a year later, this bug is still open. I sometiems need the mysql
server on my development machine, but permanently running a full-blown
database system on my everyday work laptop is a total waste of resources, so I
disabled the automatic startup of the server. That makes the postrotate script
fail - probably related to me using KDE, so there *is* a mysqld running, just
not the one the script would like to talk to.
I fixed this by adding

 test -d /var/run/mysql || exit 0 # make sure the server actually runs

at the beginning of the postrotate script. Of course this will be problematic
if the server configuration is changed to use no/a different local socket, but
it's better than daily getting a complaint mail from cron.

Kind regards,
Ralf

#544013#20
Date:
2012-07-05 15:53:12 UTC
From:
To:
Dear submitter,

as the package mysql-5.1 has just been removed from the Debian archive
unstable we hereby close the associated bug reports.  We are sorry
that we couldn't deal with your issue properly.

For details on the removal, please see http://bugs.debian.org/680362

The version of this package that was in Debian prior to this removal
can still be found using http://snapshot.debian.org/.

This message was generated automatically; if you believe that there is
a problem with it please contact the archive administrators by mailing
ftpmaster@debian.org.

Debian distribution maintenance software
pp.
Alexander Reichle-Schmehl (the ftpmaster behind the curtain)

#544013#35
Date:
2012-07-05 20:53:29 UTC
From:
To:
found 544013 mysql-server-5.5/5.5.24+dfsg-4
thanks

Normally bugs don't solve themselves by *renaming* a package. Please
reassign bugs instead of closing them.

Helmut

#544013#42
Date:
2020-07-15 22:08:24 UTC
From:
To:
Hi!

I'm experiencing the same issue as described in this bug with debian sid
and mysql-server-5.7 (5.7.26-1+b1). I noticed that one out of three times
my system boots, logrotate service fails with the following error:

```
Jul 09 07:12:01 baal systemd[1]: Starting Rotate log files...
Jul 09 07:12:01 baal logrotate[851]: error: error running shared postrotate
script for '/var/log/mysql.log /var/log/mysql/*log>
Jul 09 07:12:01 baal systemd[1]: logrotate.service: Main process exited,
code=exited, status=1/FAILURE
Jul 09 07:12:01 baal systemd[1]: logrotate.service: Failed with result
'exit-code'.
Jul 09 07:12:01 baal systemd[1]: Failed to start Rotate log files.
```

Looking at journalctl, I can see that every time this issue occurs, mysqld
is started and logrotate fails *at the same time*:

```
Jul 09 07:12:01 baal mysqld[847]: 2020-07-09T06:12:01.283924Z 0 [Note]
/usr/sbin/mysqld: ready for connections.
Jul 09 07:12:01 baal mysqld[847]: Version: '5.7.26-1+b1'  socket:
'/var/run/mysqld/mysqld.sock'  port: 3306  (Debian)
...
Jul 09 07:12:01 baal systemd[1]: logrotate.service: Main process exited,
code=exited, status=1/FAILURE
Jul 09 07:12:01 baal systemd[1]: logrotate.service: Failed with result
'exit-code'.
```

This and the fact that the issue does not reproduce every time makes me
suspect that is a race-condition between logrotate and mysqld. Looking at
the code in /etc/logrotate.d/mysql-server it seems like logrotate first
checks if mysql is running before issuing the "mysqladmin flush-logs"
command. That check is done by issuing "mysqladmin ping" (this also checks
that /etc/mysql/debian.cnf is valid). If this check fails, then it will try
to verify if the mysql process exists. If it does, then it will fail with
an exit code = 1, which causes the error messages in my logs above.
I'm sure you already noticed the issue here: what if mysqld has not started
yet by the time "mysqladmin ping" runs, but it's up right by the time
killall is executed? Apparently, this happens quite often in my system.

To fix this, I suggest reverting the checks: first validate that mysqld is
running. If not, then there is no reason to issue "mysqladmin flush-logs"
and the script can finish successfully. If mysqld is running *and*
"mysqladmin ping" fails, then it should definitely throw an error.

This approach is not completely free of race-conditions either, but it
should be more rare. I'm attaching a patch with the solution I just
described. I've had this patch applied to my system for a week and the
issue has not been reproduced since. The *best* solution would be to simply
attempt to apply "flush-logs" and react differently depending on the exit
code. Unfortunately, it seems like mysqladmin does not return different
exit codes on different errors (in my tests it always returns 1), so this
approach is not possible at the moment.

Please, apply this patch and fix this issue!

Kind regards,
Francesc

#544013#47
Date:
2020-09-06 10:57:16 UTC
From:
To:
Turns out the patch I submitted didn't fix the issue. Sorry about that.
Please ignore the patch in my previous email.

#544013#52
Date:
2025-08-22 19:12:47 UTC
From:
To:
We believe that the bug you reported is fixed in the latest version of
mysql-8.0, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 544013@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Lena Voytek <lena.voytek@canonical.com> (supplier of updated mysql-8.0 package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)
Format: 1.8
Date: Fri, 22 Aug 2025 13:53:55 -0400
Source: mysql-8.0
Built-For-Profiles: noudeb
Architecture: source
Version: 8.0.43-3
Distribution: unstable
Urgency: medium
Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Changed-By: Lena Voytek <lena.voytek@canonical.com>
Closes: 544013 621020 1006717 1092213
Changes:
 mysql-8.0 (8.0.43-3) unstable; urgency=medium
 .
   * Fix permissions and startup race condition in logrotate config.
     (Closes: #544013)
   * Update uploaders list, removing those who are no longer involved with the
     package. Thank you all for your work! (Closes: #1006717)
   * Add missing full stops to translations. (Closes: #1092213)
   * Update debian compat to 13.
     - Use dh_installsystemd to match compatibility.
     - Replace install --fail-missing with dh_missing.
   * Update standards version.
   * Remove set -e and set -u usage in init script. (Closes: #621020)
   * Clean up license text in d/copyright.
   * Remove file permissions updates in d/rules, fixed upstream.
   * Add missing symbols to symbols file.
Checksums-Sha1:
 a0bb4e982246092cec4cc4255fd3ee1dc94e64a3 3582 mysql-8.0_8.0.43-3.dsc
 6c3f2f7156047f9d04c1e4661a12e5c28177e2d1 146044 mysql-8.0_8.0.43-3.debian.tar.xz
 3a164acff0d8f7938c6db758a0278597fba08957 9123 mysql-8.0_8.0.43-3_source.buildinfo
Checksums-Sha256:
 2a64f1d4b9705f1b5926d001ac4c33c9fc307caea3d477b4c675e3ee21080d56 3582 mysql-8.0_8.0.43-3.dsc
 7917ba92c53a5529284d602cfbaa99aca473ccd6a3b1658d91584976548a44f5 146044 mysql-8.0_8.0.43-3.debian.tar.xz
 5d81ac1e6ad517be6c9b23112651359b2930bcd631adc05117ba5ef7ef3bcf01 9123 mysql-8.0_8.0.43-3_source.buildinfo
Files:
 a465f95259e4cde5820d23b921f0ab98 3582 database optional mysql-8.0_8.0.43-3.dsc
 c66640586cabbc978bfc410d219ca955 146044 database optional mysql-8.0_8.0.43-3.debian.tar.xz
 1c87d1e48617b9b4336db27afe2eb2e9 9123 database optional mysql-8.0_8.0.43-3_source.buildinfo
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEY+78PeFNUUbOfyS/NLitfZUp55MFAmiou4EACgkQNLitfZUp
55OiYxAAkByP1ax2IE/dNaueNY/D8CKjXjri1GHaggfIp3SY3a5rQPgdKln0KU/Q
ndretvxbpUao2mo0FSw6ps0zQhHLPnJv73Mt98Hlcfnzl4GRU8cBT5WHVMfd99PQ
8y1ukjpSRzIW77XJW97KPhPb4YesHQhe/DC6HL+3BYAkkewtK1bXIzFZQDhq7Z+I
5KPnrQtJzb2GvIX+hz9+JMv4Pccr93MFJvV6hJgCQIVt/lNFyxYmGVYk52n0ijiR
OnRJUSVEoVA9Uv0RcTikrrXe/yBZPK+nmlfopOHJ075VnN7B6TJdPvc/sECB9VHu
EJcnEg90CH1ebFjEOVpLqikCBaRQYLTG5n7mpryK5cakC2VgALghZz6cqWWN18cs
VUc8pMdey7Z1L2lAh7f4lZyN8nTBMKHfY0Wag/E7JCRWPN7V4nAZiIfoSCgSRXQe
8njxK/YXJyyaHQ4yg7hbubVmooHwZJMDW9JHUCNpj2tJaqjENWK3r31gXqBd3Fme
Dv3WjMn0PDqtMT/g55+RMBVDsF+l5WtjrZgiJ5JQZ0vuLIKcMfrmtbMtpGj9mjuH
h1CAIkDlUf09JWdKE8NS4tgQHtdeFmfOXji9jSB0w9jK0b5z2hUl+LSBv7NNp6jt
H0Xc5qEZ9aiLh2PFlQdrlWwDH/yY8DRlEJYhXLprFW0P0qrVa/8=
=qYi+
-----END PGP SIGNATURE-----