Hello,
I just setup a mysql slave server, and it's running smoothly, except I should manually check if the server safe to shutdown every time I need to restart or shutdown it.
This problem is related with temporary tables that master server created, as described in
mysql doc.
So, I think of making custom shell script that will automatically run each time before the slave server restart/shutdown.
The script will looks like this:
Code:
###Check the slave for Slave_open_temp_tables variable###
safe=1
(
echo "STOP SLAVE SQL_THREAD;SHOW STATUS;"
) | mysql -u USER -pPASSWORD 2>&1 | grep "Slave_open_temp_tables 0"
if [ "$?" -ne "0" ]; then
###Not Safe, need to start the sql thread###
safe=0
(
echo "START SLAVE SQL_THREAD;"
) | mysql -u USER -pPASSWORD
echo "Please try again in 30 seconds..."
fi
My question is, how to integrate this script that it will run when someone call shutdown or halt or reboot command, and when the output ("safe" variable) is 0, cancel the shutdown/restart process.