Changeset 1200

Show
Ignore:
Timestamp:
02/22/10 16:02:25 (2 years ago)
Author:
Gary
Message:

Initial working boot-cluster/boot-slave.sh script commited.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/tools/mysql-server/boot-cluster/boot-slave.sh

    r1199 r1200  
    55#       $Id$ 
    66#LEGAL 
    7 #       Copyright by Unixservice, LLC. 2010. 
     7#       Copyright Gary Wallis for Unixservice, LLC. 2010. 
    88#       GPLv2 license applies. 
    99#NOTES 
    10 #       Assume fast internal LAN cluster interconnect with passwordless ssh set up. 
     10#       Requires fast internal LAN cluster interconnect with passwordless ssh set up. 
     11#       Warning mail not implemented yet. 
    1112 
    1213#Configuration section 
    13 cMasterIP="192.168.22.128"; 
    14 cTimeoutSecs="600"; 
     14cTimeoutSecs="300"; 
    1515cWarnEmail="supportgrp@unixservice.com"; 
     16cSSHPort="22" 
    1617#end 
    1718 
    1819#our standard bash logging function. 
     20fLog() { echo "`date +%b' '%d' '%T` $0[$$]: $@"; } 
     21 
     22if [ "$1" == "" ] || [ "$2" == "" ];then 
     23        echo "usage: $0 <mysql password> <master ip>"; 
     24        exit 0; 
     25fi 
    1926 
    2027#wait for master to come up. If does not come up after cTimeoutSecs send warning email, exit error. 
     28iCounter=0; 
     29ping -c 1 $2 > /dev/null 2>&1; 
     30while [ $? != 0 ] && [ $iCounter -lt $cTimeoutSecs ];do 
     31        let iCounter=iCounter+1; 
     32        ping -c 1 $2 > /dev/null 2>&1; 
     33done 
     34if [ $iCounter -eq "$cTimeoutSecs" ];then 
     35        fLog "ping master timeout $iCounter"; 
     36        exit 1; 
     37fi 
    2138 
    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. 
     39iCounter=0; 
     40/usr/bin/ssh -p $cSSHPort $2 ps -ef | grep mysqld  > /dev/null 2>&1; 
     41while [ $? != 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; 
     45done 
     46if [ $iCounter -eq "$cTimeoutSecs" ];then 
     47        fLog "remote mysqld timeout"; 
     48        exit 2; 
     49fi 
    2950 
    3051 
    31 #start slave 
     52#master is up, get master status and parse master status. 
     53eval `/usr/bin/ssh -p $cSSHPort $2 "echo 'SHOW MASTER STATUS' | mysql -p$1 | grep mysql_binary_log" | awk '{printf"cBinLog=%s\ncPosition=%s\n",$1,$2}'`; 
     54if [ $? == 0 ]  && [ "$cBinLog" != "" ] && [ "$cPosition" != "" ];then 
    3255 
    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 
     101else 
     102        fLog "parse master status failed"; 
     103        exit 3; 
     104fi 
     105 
     106