PDA

View Full Version : problem with logrotate / mysql



teddy278
2007-07-10, 08:42
Hello world,

I've been running SlimServer on Ubuntu 6.06 Server LTS for 3 or 4 months. First couple of months, everything was fine. Then I started receiving cron-mails every day telling me something was wrong:



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


I had to restart my server (fire in the nuclear power plant 10 miles west - but hey, who cares as long as the music keeps playing? ;-)), and the cron-messages disappeard. Now they are back.

I tried to find out what the problem might be. The logrotate-script looks like this:



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

# If this fails, check debian.conf!
export HOME=/etc/mysql/my.cnf
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.$
if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
# Really no mysqld or rather a missing debian-sys-maint user?
# If this occurs and is not a error please report a bug.
if ps cax | grep -q mysqld; then
exit 1
fi
else
$MYADMIN flush-logs
fi
errlogs=`ls /var/log/mysql.err* /var/log/mysql/mysql.err* 2>/de$
if [ -n "$errlogs" ]; then
chown root:adm $errlogs
chmod 640 $errlogs
fi


It seems that logrotate checks if there is a mysqld available. If it is, it flushes its logs. If it's not available, it doublechecks whether there is a mysqld running, and if yes, kills itself with exit code 1. And that is exactly what happens.

So... how can I solve this? I thought of adding a prerotate-script running


invoke-rc.d slimserver stop

and accordingly a postrotate-script running


invoke-rc.d slimserver start

at the end of the script above. Logrotate will continue to rotate the mysql-logs but won't try to flush a mysqld that's not there. By stopping/starting SlimServer and subsequently its own mysqld, the inodes of the logfiles should be freed and reopened anyways. Right?

Since I'm not entirely fit with linux, maybe anyone out there has a better idea? I'm really a bit at a loss, these cron-error-messages start to annoy me. ;-)


Greetings!

teddy

teddy278
2007-07-11, 06:51
Hi,

am I the only one with this problem? Why does the error occour only on my system?

Anyway, I think I found a way. At the start of the mysql-server postscript I now put



invoke-rc.d --quiet slimserver stop > /dev/nul || true
while ps cax | grep -q slimserver; do
sleep 5
done


That stops slimserver without any messages and then waits until the slimserver-process is gone.

At the end, of course, this:



invoke-rc.d --quiet slimserver start > /dev/nul || true


Testrun works so far, but maybe I have missed something. What do you think?


Bye,
teddy