vitess.io/vitess@v0.16.2/examples/common/scripts/vtadmin-up.sh (about) 1 #!/bin/bash 2 3 script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" 4 source "${script_dir}/../env.sh" 5 6 cluster_name="local" 7 log_dir="${VTDATAROOT}/tmp" 8 web_dir="${script_dir}/../../../web/vtadmin" 9 10 vtadmin_api_port=14200 11 vtadmin_web_port=14201 12 13 vtadmin \ 14 --addr ":${vtadmin_api_port}" \ 15 --http-origin "http://localhost:${vtadmin_web_port}" \ 16 --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ 17 --tracer "opentracing-jaeger" \ 18 --grpc-tracing \ 19 --http-tracing \ 20 --logtostderr \ 21 --alsologtostderr \ 22 --rbac \ 23 --rbac-config="${script_dir}/../vtadmin/rbac.yaml" \ 24 --cluster "id=${cluster_name},name=${cluster_name},discovery=staticfile,discovery-staticfile-path=${script_dir}/../vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ 25 > "${log_dir}/vtadmin-api.out" 2>&1 & 26 27 vtadmin_api_pid=$! 28 echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid" 29 30 echo "\ 31 vtadmin-api is running! 32 - API: http://localhost:${vtadmin_api_port} 33 - Logs: ${log_dir}/vtadmin-api.out 34 - PID: ${vtadmin_api_pid} 35 " 36 37 # Wait for vtadmin to successfully discover the cluster 38 expected_cluster_result="{\"result\":{\"clusters\":[{\"id\":\"${cluster_name}\",\"name\":\"${cluster_name}\"}]},\"ok\":true}" 39 for _ in {0..300}; do 40 result=$(curl -s "http://localhost:${vtadmin_api_port}/api/clusters") 41 if [[ ${result} == "${expected_cluster_result}" ]]; then 42 break 43 fi 44 sleep 0.1 45 done 46 47 # Check one last time 48 [[ $(curl -s "http://localhost:${vtadmin_api_port}/api/clusters") == "${expected_cluster_result}" ]] || fail "vtadmin failed to discover the running example Vitess cluster." 49 50 # As a TODO, it'd be nice to make the assumption that vtadmin-web is already 51 # installed and built (since we assume that `make` has already been run for 52 # other Vitess components.) 53 npm --prefix "$web_dir" --silent install 54 55 REACT_APP_VTADMIN_API_ADDRESS="http://localhost:${vtadmin_api_port}" \ 56 REACT_APP_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ 57 npm run --prefix "$web_dir" build 58 59 "${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \ 60 > "${log_dir}/vtadmin-web.out" 2>&1 & 61 62 vtadmin_web_pid=$! 63 echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid" 64 65 echo "\ 66 vtadmin-web is running! 67 - Browser: http://localhost:${vtadmin_web_port} 68 - Logs: ${log_dir}/vtadmin-web.out 69 - PID: ${vtadmin_web_pid} 70 "