Comment 2 for bug 1025536

Revision history for this message
Volans (volans) wrote :

The logic is fine, but the script uses mysqladmin to flush logs so is possible that the mysqladmin binary is missing or not anymore executable while mysqld is running. In this case the script will rotate logs without flushing and will be no error message about this corner case situation in /var/log/messages.

For this reason I suggested to move some sanity checks to the prerotate, like this one:

    test -x /usr/bin/mysqladmin || exit 0

Changing also the "exit 0" with another exit value in order to log into /var/log/messages the error.

Maybe I'm wrong, but it seems to me that the script can handle the following situations:
  1) Mysqladmin ping is OK => flush logs
  2) Mysqladmin ping is KO AND no running process => exit 1
  3) Mysqladmin ping is KO AND there is a running process => exit 0

I think that the case (2) should exit with a 0 value, because in this case simply MySQL was stopped and I don't see any reason to log into messages this as an error. I suspect that the check "if ps cax | grep -q mysqld; then" is wrong, because the exit value of grep in this case is "0" if a mysqld process exists and "1" if it not exists.

For the same reason the case (3) should have an exit status > 0 because this is a problem.

Also the grep check is unsafe, can match many other processes, I suggest to use:

    pgrep '^mysqld$'

for a safer check.

Moreover I strongly suggest to add the directive "notifempty" to the logrotate script in order to avoid useless rotation of empty log files that can quickly lead to a lost of the useful ones due to the daily rotation directive. (why not weekly?)