vitess.io/vitess@v0.16.2/docker/mini/vttablet-mini-up.sh (about) 1 #!/bin/bash 2 3 # Copyright 2019 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 mysql_host="$1" 18 mysql_port="$2" 19 is_primary="$3" 20 21 source ./env.sh 22 23 cell=${CELL:-'test'} 24 keyspace=${KEYSPACE:-'test_keyspace'} 25 shard=${SHARD:-'0'} 26 uid=$TABLET_UID 27 port=$[15000 + $TABLET_UID] 28 grpc_port=$[16000 + $uid] 29 printf -v alias '%s-%010d' $cell $uid 30 printf -v tablet_dir 'vt_%010d' $uid 31 tablet_hostname="$mysql_host" 32 printf -v tablet_logfile 'vttablet_%010d_querylog.txt' $uid 33 34 mkdir -p "$VTDATAROOT/$tablet_dir" 35 36 tablet_type=replica 37 38 echo "> Starting vttablet for server $mysql_host:$mysql_port" 39 echo " - Tablet alias is $alias" 40 echo " - Tablet listens on http://$hostname:$port" 41 # shellcheck disable=SC2086 42 vttablet \ 43 $TOPOLOGY_FLAGS \ 44 -log_dir $VTDATAROOT/tmp \ 45 -log_queries_to_file $VTDATAROOT/tmp/$tablet_logfile \ 46 -tablet-path $alias \ 47 -tablet_hostname "$hostname" \ 48 -init_db_name_override "$keyspace" \ 49 -init_keyspace $keyspace \ 50 -init_shard $shard \ 51 -init_tablet_type $tablet_type \ 52 -health_check_interval 5s \ 53 -enable_replication_reporter \ 54 -backup_storage_implementation file \ 55 -file_backup_storage_root $VTDATAROOT/backups \ 56 -port $port \ 57 -grpc_port $grpc_port \ 58 -db_host $mysql_host \ 59 -db_port $mysql_port \ 60 -db_app_user $TOPOLOGY_USER \ 61 -db_app_password $TOPOLOGY_PASSWORD \ 62 -db_dba_user $TOPOLOGY_USER \ 63 -db_dba_password $TOPOLOGY_PASSWORD \ 64 -mycnf_mysql_port $mysql_port \ 65 -service_map 'grpc-queryservice,grpc-tabletmanager,grpc-updatestream' \ 66 -pid_file $VTDATAROOT/$tablet_dir/vttablet.pid \ 67 -vtctld_addr http://$hostname:$vtctld_web_port/ \ 68 > $VTDATAROOT/$tablet_dir/vttablet.out 2>&1 & 69 70 # Block waiting for the tablet to be listening 71 # Not the same as healthy 72 73 for i in $(seq 0 300); do 74 curl -I "http://$hostname:$port/debug/status" >/dev/null 2>&1 && break 75 sleep 0.1 76 done 77 78 # check one last time 79 curl -I "http://$hostname:$port/debug/status" >/dev/null 2>&1 || fail "tablet could not be started!" 80 81 echo " + vttablet started" 82 83 if [ "$is_primary" == "true" ] ; then 84 echo " > Setting this tablet as primary" 85 vtctlclient TabletExternallyReparented "$alias" && 86 echo " + done" 87 fi