Logrotate script check after rotate

Bug #1025536 reported by Volans
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
Triaged
Low
Unassigned
5.1
Won't Fix
Low
Unassigned
5.5
Triaged
Low
Unassigned
Percona XtraDB Cluster moved to https://jira.percona.com/projects/PXC
Status tracked in 5.6
5.5
Confirmed
Medium
Unassigned
5.6
Confirmed
Medium
Unassigned

Bug Description

Installing Percona Server 5.5 from the APT repository a Logrotate script is installed in /etc/logrotate.d/percona-server-server-5.5.

The logrotate script do it's sanity checks only after the logs were rotated (in postrotate directive) and not in the prerotate directive.

With this configuration is possible that the log files were rotated by the logrotate script but the FLUSH LOGS command will not be executed in MySQL if the sanity checks do not passes.

Tags: pkg
Revision history for this message
Raghavendra D Prabhu (raghavendra-prabhu) wrote :

 The logic in the script being to rotate, and then flush logs only if mysql is up. Shouldn't this be fine? (otherwise if mysql is not up it may not rotate, if you check in prerotate etc.)

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?)

Revision history for this message
Valerii Kravchuk (valerii-kravchuk) wrote :

In both current 5.1 and 5.5 branches of percona-server mysql-log-rotate script looks like the following:

...
/home/openxs/dbs/p5.5/data/mysqld.log {
        # create 600 mysql mysql
        notifempty
        daily
        rotate 3
        missingok
        compress
    postrotate
        # just if mysqld is really running
        if test -x /home/openxs/dbs/p5.5/bin/mysqladmin && \
           /home/openxs/dbs/p5.5/bin/mysqladmin ping &>/dev/null
        then
           /home/openxs/dbs/p5.5/bin/mysqladmin flush-logs
        fi
    endscript
}

So, no prerotate checks are made and some of concerns expressed in the last comment looks still valid.

Changed in percona-server:
status: New → Confirmed
Revision history for this message
Nilnandan Joshi (nilnandan-joshi) wrote :

Checked the same in mysql-log-rotate.sh for PXC 5.5 and PXC 5.6

@localstatedir@/mysqld.log {
        # create 600 mysql mysql
        notifempty
 daily
        rotate 3
        missingok
        compress
    postrotate
 # just if mysqld is really running
 if test -x @bindir@/mysqladmin && \
    @bindir@/mysqladmin ping &>/dev/null
 then
    @bindir@/mysqladmin flush-logs
 fi
    endscript
}

tags: added: pkg
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PXC-1039

Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-1926

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.