Issues with logrotate postrotate script
Posted by: Bryan Tyler
Date: March 20, 2014 09:16AM

Hi everyone,

I'm having an issue with my logrotate script for mysql.

The system is RHEL 6.3, MySQL 5.1.67

I have the logrotate script in /etc/logrotate.d/ called mysqld

The script looks like this:

/var/log/mysqld.log /var/log/slow-query.log /var/log/mysqld_general.log {
create 0644 mysql mysql
daily
rotate 7
missingok
notifempty
dateext
postrotate
if
/usr/bin/mysqladmin ping &>/dev/null
then
/usr/bin/mysqladmin --defaults-file=/root/.my.cnf flush-logs 2>&1 | tee /var/log/messages
fi
endscript
}

I have the /root/.my.cnf file set up with perms (600 root:root)

With the following contents:

[mysqladmin]
password=<root mysql password>
user=root

I have confirmed that I can log in to mysql with the credentials supplied in .my.cnf and I can run the postrotate commands interactively.

The issue is that when the cron runs, I receive the following messages in /var/log/messages:

Could not open required defaults file: /root/.my.cnf
Fatal error in defaults handling. Program aborted
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

The logs themselves rotate; however, the flush-logs command obviously isn't working, so mysql continues to write to the old log until I issue the command interactively.

Thanks!

Options: ReplyQuote


Subject
Written By
Posted
Issues with logrotate postrotate script
March 20, 2014 09:16AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.