| 22 | | #master is up, get master status. |
| 23 | | |
| 24 | | #parse master status. |
| 25 | | |
| 26 | | #make sure slave mode is off. |
| 27 | | |
| 28 | | #SQL "change master to" parsed data on local slave MySQL server. |
| | 39 | iCounter=0; |
| | 40 | /usr/bin/ssh -p $cSSHPort $2 ps -ef | grep mysqld > /dev/null 2>&1; |
| | 41 | while [ $? != 0 ] && [ $iCounter -lt $cTimeoutSecs ];do |
| | 42 | let iCounter=iCounter+1; |
| | 43 | /usr/bin/ssh -p $cSSHPort $2 ps -ef | grep mysqld > /dev/null 2>&1; |
| | 44 | sleep 1; |
| | 45 | done |
| | 46 | if [ $iCounter -eq "$cTimeoutSecs" ];then |
| | 47 | fLog "remote mysqld timeout"; |
| | 48 | exit 2; |
| | 49 | fi |
| 33 | | #check status. if slave did not catch up in max cTimeoutSecs send warning email, exit error. |
| | 56 | #make sure slave mode is off. |
| | 57 | echo "STOP SLAVE" | mysql -p$1 > /dev/null 2>&1; |
| | 58 | if [ $? != 0 ];then |
| | 59 | fLog "local slave stop failed"; |
| | 60 | exit 4; |
| | 61 | fi |
| | 62 | |
| | 63 | #SQL "change master to" parsed data on local slave MySQL server. |
| | 64 | echo "CHANGE MASTER TO MASTER_LOG_FILE='$cBinLog',MASTER_LOG_POS=$cPosition" | mysql -p$1 > /dev/null 2>&1; |
| | 65 | if [ $? != 0 ];then |
| | 66 | fLog "local change master failed"; |
| | 67 | exit 5; |
| | 68 | fi |
| | 69 | |
| | 70 | #start slave |
| | 71 | echo "START SLAVE" | mysql -p$1 > /dev/null 2>&1; |
| | 72 | if [ $? != 0 ];then |
| | 73 | fLog "local slave stop failed"; |
| | 74 | exit 6; |
| | 75 | fi |
| | 76 | |
| | 77 | #check status. if slave did not catch up in max cTimeoutSecs send warning email, exit error. |
| | 78 | eval `echo "SHOW SLAVE STATUS\G" | mysql -p$1 | grep Seconds_Behind_Master | awk '{printf"iSecondsBehindMaster=%s\n",$2}'`; |
| | 79 | if [ $? != 0 ];then |
| | 80 | fLog "show local slave status failed"; |
| | 81 | exit 7; |
| | 82 | fi |
| | 83 | #echo $iSecondsBehindMaster; |
| | 84 | iCounter=0; |
| | 85 | while [ $iCounter -lt $cTimeoutSecs ] && [ $iSecondsBehindMaster -gt "0" ];do |
| | 86 | let iCounter=iCounter+1; |
| | 87 | eval `echo "SHOW SLAVE STATUS\G" | mysql -p$1 | grep Seconds_Behind_Master | awk '{printf"iSecondsBehindMaster=%s\n",$2}'`; |
| | 88 | if [ $? != 0 ];then |
| | 89 | fLog "show local slave status failed"; |
| | 90 | exit 8; |
| | 91 | fi |
| | 92 | #double the timeout for long catch-up |
| | 93 | sleep 2; |
| | 94 | done |
| | 95 | if [ $iCounter -eq "$cTimeoutSecs" ];then |
| | 96 | fLog "local slave catch-up timeout"; |
| | 97 | exit 9; |
| | 98 | fi |
| | 99 | |
| | 100 | |
| | 101 | else |
| | 102 | fLog "parse master status failed"; |
| | 103 | exit 3; |
| | 104 | fi |
| | 105 | |
| | 106 | |