vitess.io/vitess@v0.16.2/examples/common/env.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 source "$(dirname "${BASH_SOURCE[0]:-$0}")/lib/utils.sh" 18 19 hostname=$(hostname -f) 20 vtctld_web_port=15000 21 export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}" 22 23 if [[ $EUID -eq 0 ]]; then 24 fail "This script refuses to be run as root. Please switch to a regular user." 25 fi 26 27 # mysqld might be in /usr/sbin which will not be in the default PATH 28 PATH="/usr/sbin:$PATH" 29 for binary in mysqld etcd etcdctl curl vtctlclient vttablet vtgate vtctld mysqlctl; do 30 command -v "$binary" > /dev/null || fail "${binary} is not installed in PATH. See https://vitess.io/docs/get-started/local/ for install instructions." 31 done; 32 33 if [ "${TOPO}" = "zk2" ]; then 34 # Each ZooKeeper server needs a list of all servers in the quorum. 35 # Since we're running them all locally, we need to give them unique ports. 36 # In a real deployment, these should be on different machines, and their 37 # respective hostnames should be given. 38 zkcfg=(\ 39 "1@$hostname:28881:38881:21811" \ 40 "2@$hostname:28882:38882:21812" \ 41 "3@$hostname:28883:38883:21813" \ 42 ) 43 printf -v zkcfg ",%s" "${zkcfg[@]}" 44 zkcfg=${zkcfg:1} 45 46 zkids='1 2 3' 47 48 # Set topology environment parameters. 49 ZK_SERVER="localhost:21811,localhost:21812,localhost:21813" 50 # shellcheck disable=SC2034 51 TOPOLOGY_FLAGS="--topo_implementation zk2 --topo_global_server_address ${ZK_SERVER} --topo_global_root /vitess/global" 52 53 mkdir -p "${VTDATAROOT}/tmp" 54 elif [ "${TOPO}" = "k8s" ]; then 55 # Set topology environment parameters. 56 K8S_ADDR="localhost" 57 K8S_PORT="8443" 58 K8S_KUBECONFIG=$VTDATAROOT/tmp/k8s.kubeconfig 59 # shellcheck disable=SC2034 60 TOPOLOGY_FLAGS="--topo_implementation k8s --topo_k8s_kubeconfig ${K8S_KUBECONFIG} --topo_global_server_address ${K8S_ADDR}:${K8S_PORT} --topo_global_root /vitess/global" 61 elif [ "${TOPO}" = "consul" ]; then 62 # Set up topology environment parameters. 63 CONSUL_SERVER=127.0.0.1 64 CONSUL_HTTP_PORT=8500 65 CONSUL_SERVER_PORT=8300 66 TOPOLOGY_FLAGS="--topo_implementation consul --topo_global_server_address ${CONSUL_SERVER}:${CONSUL_HTTP_PORT} --topo_global_root vitess/global/" 67 mkdir -p "${VTDATAROOT}/consul" 68 else 69 ETCD_SERVER="localhost:2379" 70 TOPOLOGY_FLAGS="--topo_implementation etcd2 --topo_global_server_address $ETCD_SERVER --topo_global_root /vitess/global" 71 72 mkdir -p "${VTDATAROOT}/etcd" 73 fi 74 75 mkdir -p "${VTDATAROOT}/tmp" 76 77 # Set aliases to simplify instructions. 78 # In your own environment you may prefer to use config files, 79 # such as ~/.my.cnf 80 81 alias mysql="command mysql --no-defaults -h 127.0.0.1 -P 15306" 82 alias vtctlclient="command vtctlclient --server localhost:15999 --log_dir ${VTDATAROOT}/tmp --alsologtostderr" 83 alias vtctldclient="command vtctldclient --server localhost:15999" 84 85 # Make sure aliases are expanded in non-interactive shell 86 shopt -s expand_aliases 87