|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2023 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 | +function output() { |
| 18 | + echo -e "$@" |
| 19 | +} |
| 20 | + |
| 21 | +script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" |
| 22 | +source "${script_dir}/../env.sh" |
| 23 | + |
| 24 | +cluster_name="local" |
| 25 | +log_dir="${VTDATAROOT}/tmp" |
| 26 | +web_dir="${script_dir}/../../../web/vtadmin" |
| 27 | + |
| 28 | +vtadmin_api_port=14200 |
| 29 | +vtadmin_web_port=14201 |
| 30 | + |
| 31 | +case_insensitive_hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') |
| 32 | + |
| 33 | +output "\n\033[1;32mvtadmin-api expects vtadmin-web at, and set http-origin to \"http://${case_insensitive_hostname}:${vtadmin_web_port}\"\033[0m" |
| 34 | + |
| 35 | +vtadmin \ |
| 36 | + --addr "${case_insensitive_hostname}:${vtadmin_api_port}" \ |
| 37 | + --http-origin "http://${case_insensitive_hostname}:${vtadmin_web_port}" \ |
| 38 | + --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ |
| 39 | + --tracer "opentracing-jaeger" \ |
| 40 | + --grpc-tracing \ |
| 41 | + --http-tracing \ |
| 42 | + --logtostderr \ |
| 43 | + --alsologtostderr \ |
| 44 | + --rbac \ |
| 45 | + --rbac-config="${script_dir}/../vtadmin/rbac.yaml" \ |
| 46 | + --cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl=http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }},schema-cache-default-expiration=1m" \ |
| 47 | + > "${log_dir}/vtadmin-api.out" 2>&1 & |
| 48 | + |
| 49 | +vtadmin_api_pid=$! |
| 50 | +echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid" |
| 51 | + |
| 52 | +echo "\ |
| 53 | +vtadmin-api is running! |
| 54 | + - API: http://${case_insensitive_hostname}:${vtadmin_api_port} |
| 55 | + - Logs: ${log_dir}/vtadmin-api.out |
| 56 | + - PID: ${vtadmin_api_pid} |
| 57 | +" |
| 58 | + |
| 59 | +echo "Building vtadmin-web..." |
| 60 | +source "${web_dir}/build.sh" |
| 61 | + |
| 62 | +# Wait for vtadmin to successfully discover the cluster |
| 63 | +expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" |
| 64 | +for _ in {0..100}; do |
| 65 | + result=$(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters") |
| 66 | + if [[ ${result} == "${expected_cluster_result}" ]]; then |
| 67 | + break |
| 68 | + fi |
| 69 | + sleep 0.1 |
| 70 | +done |
| 71 | + |
| 72 | +# Check one last time |
| 73 | +[[ $(curl -s "http://${case_insensitive_hostname}:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." |
| 74 | + |
| 75 | +[[ ! -d "$web_dir/build" ]] && fail "Please make sure the VTAdmin files are built in $web_dir/build, using 'make build'" |
| 76 | + |
| 77 | +"${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \ |
| 78 | + > "${log_dir}/vtadmin-web.out" 2>&1 & |
| 79 | + |
| 80 | +vtadmin_web_pid=$! |
| 81 | +echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid" |
| 82 | + |
| 83 | +echo "\ |
| 84 | +vtadmin-web is running! |
| 85 | + - Browser: http://${case_insensitive_hostname}:${vtadmin_web_port} |
| 86 | + - Logs: ${log_dir}/vtadmin-web.out |
| 87 | + - PID: ${vtadmin_web_pid} |
| 88 | +" |
0 commit comments