| 70 | |
| 71 | After wake up, we need to start docker database and sync to mysql group replication. In command '''docker exec -i''', we use only '''-i''' not '''-it''' because '''-t''' was a tty console when run as a script it was not from tty console so we need to use only '''-i''' (interactive mode) |
| 72 | {{{ |
| 73 | #!/usr/bin/bash |
| 74 | |
| 75 | logfile=/tmp/nodedb1.log |
| 76 | container_name=nodedb1 |
| 77 | /usr/bin/docker start $container_name |
| 78 | echo "docker start $container_name" >> $logfile |
| 79 | sleep 10 |
| 80 | if [ "$( docker container inspect -f '{{.State.Status}}' $container_name )" == "running" ]; then |
| 81 | echo "$container_name is running" >> $logfile |
| 82 | else |
| 83 | echo "$container_name is not running, we will start again" >> $logfile |
| 84 | /usr/bin/docker start $container_name |
| 85 | echo "start $container_name Done!!" >> $logfile |
| 86 | fi |
| 87 | |
| 88 | if [ "$( docker container inspect -f '{{.State.Status}}' $container_name )" == "running" ]; then |
| 89 | cmd1="/usr/bin/docker exec -i $container_name mysql -uroot -pmypass -e \"STOP GROUP_REPLICATION;\" \ |
| 90 | -e \"SET @@GLOBAL.group_replication_group_name='aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';\" \ |
| 91 | -e \"SET @@GLOBAL.group_replication_local_address='$container_name:33061';\"\ |
| 92 | -e \"SET @@GLOBAL.group_replication_group_seeds='$container_name:33061,nodedb2:33061,nodedb3:33061';\" \ |
| 93 | -e \"change master to master_user='repl' for channel 'group_replication_recovery';\" \ |
| 94 | -e \"START GROUP_REPLICATION;\" " |
| 95 | echo "$cmd1" >> $logfile |
| 96 | eval "$cmd1" 2> /tmp/err.log 1>> $logfile |
| 97 | sleep 10 |
| 98 | echo "$container_name join group_replication" >> $logfile |
| 99 | cmd2="/usr/bin/docker exec -i $container_name mysql -uroot -pmypass -e \"SELECT * FROM performance_schema.replication_group_members;\" " |
| 100 | echo "$cmd2" >> $logfile |
| 101 | eval "$cmd2" 2> /tmp/err.log 1>> $logfile |
| 102 | else |
| 103 | echo "$container_name still not start" >> $logfile |
| 104 | fi |
| 105 | |
| 106 | }}} |