vitess.io/vitess@v0.16.2/examples/common/scripts/etcd-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 # This is an example script that creates a quorum of Etcd servers. 18 19 source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" 20 21 cell=${CELL:-'test'} 22 export ETCDCTL_API=2 23 24 # Check that etcd is not already running 25 curl "http://${ETCD_SERVER}" > /dev/null 2>&1 && fail "etcd is already running. Exiting." 26 27 etcd --enable-v2=true --data-dir "${VTDATAROOT}/etcd/" --listen-client-urls "http://${ETCD_SERVER}" --advertise-client-urls "http://${ETCD_SERVER}" > "${VTDATAROOT}"/tmp/etcd.out 2>&1 & 28 PID=$! 29 echo $PID > "${VTDATAROOT}/tmp/etcd.pid" 30 sleep 5 31 32 echo "add /vitess/global" 33 etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/global & 34 35 echo "add /vitess/$cell" 36 etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/$cell & 37 38 # And also add the CellInfo description for the cell. 39 # If the node already exists, it's fine, means we used existing data. 40 echo "add $cell CellInfo" 41 set +e 42 # shellcheck disable=SC2086 43 vtctl $TOPOLOGY_FLAGS VtctldCommand AddCellInfo \ 44 --root /vitess/$cell \ 45 --server-address "${ETCD_SERVER}" \ 46 $cell 47 set -e 48 49 echo "etcd start done..." 50 51