Skip to content

Commit

Permalink
Improve vtadmin-{up,down}.sh scripts for the local example (vitessio#…
Browse files Browse the repository at this point in the history
…10081)

Signed-off-by: Sara Bee <855595+doeg@users.noreply.github.com>
  • Loading branch information
doeg authored Apr 20, 2022
1 parent 93f4490 commit b211c7b
Show file tree
Hide file tree
Showing 5 changed files with 1,015 additions and 16 deletions.
2 changes: 2 additions & 0 deletions examples/local/401_teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ else
CELL=zone1 ./scripts/etcd-down.sh
fi

./scripts/vtadmin-down.sh

# pedantic check: grep for any remaining processes

if [ ! -z "$VTDATAROOT" ]; then
Expand Down
9 changes: 9 additions & 0 deletions examples/local/scripts/vtadmin-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

source ./env.sh

echo "Stopping vtadmin-web..."
kill -9 "$(cat "$VTDATAROOT/tmp/vtadmin-web.pid")"

echo "Stopping vtadmin-api..."
kill -9 "$(cat "$VTDATAROOT/tmp/vtadmin-api.pid")"
47 changes: 31 additions & 16 deletions examples/local/scripts/vtadmin-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
source ./env.sh

log_dir="${VTDATAROOT}/tmp"
web_dir="../../web/vtadmin"

vtadmin_api_port=14200
vtadmin_web_port=14201

vtadmin \
--addr ":${vtadmin_api_port}" \
--http-origin "http://localhost:3000" \
--http-origin "http://localhost:${vtadmin_web_port}" \
--http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
--tracer "opentracing-jaeger" \
--grpc-tracing \
Expand All @@ -18,23 +21,35 @@ vtadmin \
--rbac-config="./vtadmin/rbac.yaml" \
--cluster "id=local,name=local,discovery=staticfile,discovery-staticfile-path=./vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \
> "${log_dir}/vtadmin-api.out" 2>&1 &
vtadmin_pid=$!

function cleanup() {
kill -9 "${vtadmin_pid}"

echo
echo "Shutdown complete!"
}
vtadmin_api_pid=$!
echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid"

trap cleanup INT QUIT TERM
echo "\
vtadmin-api is running!
- API: http://localhost:${vtadmin_api_port}
- Logs: ${log_dir}/vtadmin-api.out
- PID: ${vtadmin_api_pid}
"

echo "vtadmin-api is running on http://localhost:${vtadmin_api_port}. Logs are in ${log_dir}/vtadmin-api.out, and its PID is ${vtadmin_pid}"
# As a TODO, it'd be nice to make the assumption that vtadmin-web is already
# installed and built (since we assume that `make` has already been run for
# other Vitess components.)
npm --prefix $web_dir --silent install

(
cd ../../web/vtadmin &&
npm install &&
REACT_APP_VTADMIN_API_ADDRESS="http://127.0.0.1:${vtadmin_api_port}" \
REACT_APP_VTADMIN_API_ADDRESS="http://localhost:${vtadmin_api_port}" \
REACT_APP_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \
npm run start
)
npm run --prefix $web_dir build

"${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \
> "${log_dir}/vtadmin-web.out" 2>&1 &

vtadmin_web_pid=$!
echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid"

echo "\
vtadmin-web is running!
- Browser: http://localhost:${vtadmin_web_port}
- Logs: ${log_dir}/vtadmin-web.out
- PID: ${vtadmin_web_pid}
"
Loading

0 comments on commit b211c7b

Please sign in to comment.