vitess.io/vitess@v0.16.2/docker/mini/docker-entry (about) 1 #!/bin/bash 2 3 # Copyright 2020 The Vitess Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 # This script probes for an existing MySQL topologies and sets up a mini vitess setup matching that topology. 18 # 19 20 echo_sleep() { 21 local SECONDS="$1" 22 for i in $(seq 1 $SECONDS) ; do 23 echo -n "." 24 sleep 1 25 done 26 echo 27 } 28 29 echo_header() { 30 local HEADER="$1" 31 echo "" 32 echo "# $HEADER" 33 } 34 35 SCRIPTS_PATH="/vt/dist/scripts" 36 export CELL=${CELL:-zone1} 37 export $TOPOLOGY_USER 38 export $TOPOLOGY_PASSWORD 39 40 41 cat <<- "EOF" 42 ============================================= 43 44 | \/ (_)_ __ (_) \ / (_) |_ ___ ___ ___ 45 | |\/| | | '_ \| |\ \ / /| | __/ _ \/ __/ __| 46 | | | | | | | | | \ V / | | || __/\__ \__ \ 47 |_| |_|_|_| |_|_| \_/ |_|\__\___||___/___/ 48 49 ============================================= 50 EOF 51 52 if [ -z "$MYSQL_SCHEMA" ] ; then 53 echo "Expected MYSQL_SCHEMA environment variable" 54 exit 1 55 fi 56 if [ -z "$TOPOLOGY_SERVER" ] ; then 57 echo "TOPOLOGY_SERVER environment variable not found. You must specify a MySQL server within your topology." 58 echo "This mini-vitess setup will attempt to discover your topology using that server and will bootstrap to match your topology" 59 exit 1 60 fi 61 if [ -z "$TOPOLOGY_USER" ] ; then 62 echo "TOPOLOGY_USER environment variable not found. You must specify a MySQL username accessible to vitess." 63 exit 1 64 fi 65 if [ -z "$TOPOLOGY_PASSWORD" ] ; then 66 echo "TOPOLOGY_PASSWORD environment variable not found. You must specify a MySQL password accessible to vitess." 67 exit 1 68 fi 69 70 echo "MiniVitess is starting up..." 71 echo "- Given MySQL topology server: $TOPOLOGY_SERVER" 72 echo "- Given MySQL schema: $MYSQL_SCHEMA" 73 74 cd $SCRIPTS_PATH 75 76 source ./env.sh 77 78 echo_header "orchestrator" 79 ./orchestrator-up.sh 80 echo "- orchestrator will meanwhile probe and map your MySQL replication topology" 81 82 echo_header "etcd" 83 ./etcd-up.sh 84 85 echo_header "vtctld" 86 ./vtctld-mini-up.sh 87 88 echo_header "Waiting for topology to be detected and analyzed" 89 echo_sleep 15 90 91 echo_header "orchestrator has detected the following MySQL servers:" 92 orchestrator-client -c all-instances 93 94 echo_header "Bootstrapping vttablets for the above instances..." 95 96 BASE_TABLET_UID=100 97 for i in $(orchestrator-client -c all-instances) ; do 98 read -r mysql_host mysql_port <<<$(echo $i | tr ':' ' ') 99 100 is_primary="" 101 if [ "$i" == "$(orchestrator-client -c which-cluster-master -i "$i")" ] ; then 102 is_primary="true" 103 fi 104 105 KEYSPACE=$MYSQL_SCHEMA TABLET_UID=$BASE_TABLET_UID ./vttablet-mini-up.sh "$mysql_host" "$mysql_port" "$is_primary" 106 BASE_TABLET_UID=$((BASE_TABLET_UID + 1)) 107 done 108 109 echo_header "vtgate" 110 ./vtgate-up.sh 111 112 echo_header "Setup complete" 113 114 echo_header "Your topology is:" 115 orchestrator-client -c topology-tabulated -i ${TOPOLOGY_SERVER} | tr '|' ' ' 116 117 echo_header "vtgate is listening for MySQL connection on port 15306" 118 119 echo_header "On this container, try running any of the following commands:" 120 echo " mysql ${MYSQL_SCHEMA} -e 'show tables'" 121 echo " mysql ${MYSQL_SCHEMA}@primary -e 'select @@hostname, @@port'" 122 echo " mysql ${MYSQL_SCHEMA}@replica -e 'select @@hostname, @@port'" 123 124 echo_header "Outside this container, try running any of the following commands:" 125 echo " mysql -h $(hostname) --port=15306 ${MYSQL_SCHEMA} -e 'show tables'" 126 echo " mysql -h $(hostname) --port=15306 ${MYSQL_SCHEMA}@primary -e 'select @@hostname, @@port'" 127 echo " mysql -h $(hostname) --port=15306 ${MYSQL_SCHEMA}@replica -e 'select @@hostname, @@port'" 128 129 echo_header "Ready" 130 131 echo "" 132