vitess.io/vitess@v0.16.2/examples/common/scripts/consul-up.sh (about) 1 #!/bin/bash 2 3 # Copyright 2022 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 single-node consul datacenter. 18 19 source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" 20 21 cell=${CELL:-'test'} 22 consul_http_port=${CONSUL_HTTP_PORT:-'8500'} 23 consul_server_port=${CONSUL_SERVER_PORT:-'8300'} 24 25 # Check that consul is not already running 26 curl "http://${CONSUL_SERVER}:${consul_http_port}" &> /dev/null && fail "consul is already running. Exiting." 27 28 set -x 29 consul agent \ 30 -server \ 31 -bootstrap-expect=1 \ 32 -node=vitess-consul \ 33 -bind="${CONSUL_SERVER}" \ 34 -server-port="${consul_server_port}" \ 35 -data-dir="${VTDATAROOT}/consul/" -ui > "${VTDATAROOT}/tmp/consul.out" 2>&1 & 36 37 PID=$! 38 echo $PID > "${VTDATAROOT}/tmp/consul.pid" 39 sleep 5 40 41 # Add the CellInfo description for the cell. 42 # If the node already exists, it's fine, means we used existing data. 43 echo "add $cell CellInfo" 44 set +e 45 # shellcheck disable=SC2086 46 vtctl $TOPOLOGY_FLAGS VtctldCommand AddCellInfo \ 47 --root "vitess/$cell" \ 48 --server-address "${CONSUL_SERVER}:${consul_http_port}" \ 49 "$cell" 50 set -e 51 52 echo "consul start done..."