fix: harden demo lifecycle and scanner
This commit is contained in:
+25
-10
@@ -4,16 +4,26 @@ set -euo pipefail
|
||||
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
# shellcheck source=process-lib.sh
|
||||
source "$ROOT/tools/process-lib.sh"
|
||||
ANVIL_TEST_PHRASE='test test test test test test test test test test test junk'
|
||||
ANVIL_DEV_WORDS=(test test test test test test test test test test test junk)
|
||||
CLEANING=0
|
||||
ANVIL_PID='' ANVIL_START='' ANVIL_PGID=''
|
||||
VITE_PID='' VITE_START='' VITE_PGID=''
|
||||
|
||||
cleanup() {
|
||||
local status=$? cleanup_status=0
|
||||
((CLEANING == 0)) || return
|
||||
CLEANING=1
|
||||
trap - INT TERM EXIT
|
||||
demo_stop_recorded "$ROOT" vite || cleanup_status=1
|
||||
demo_stop_recorded "$ROOT" anvil || cleanup_status=1
|
||||
if [[ -n "$VITE_PID" && -n "$VITE_START" && -n "$VITE_PGID" ]]; then
|
||||
demo_stop_launch "$ROOT" vite "$VITE_PID" "$VITE_START" "$VITE_PGID" || cleanup_status=1
|
||||
else
|
||||
demo_stop_recorded "$ROOT" vite || cleanup_status=1
|
||||
fi
|
||||
if [[ -n "$ANVIL_PID" && -n "$ANVIL_START" && -n "$ANVIL_PGID" ]]; then
|
||||
demo_stop_launch "$ROOT" anvil "$ANVIL_PID" "$ANVIL_START" "$ANVIL_PGID" || cleanup_status=1
|
||||
else
|
||||
demo_stop_recorded "$ROOT" anvil || cleanup_status=1
|
||||
fi
|
||||
((status == 0 && cleanup_status != 0)) && status=$cleanup_status
|
||||
exit "$status"
|
||||
}
|
||||
@@ -21,14 +31,19 @@ trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
trap cleanup EXIT
|
||||
|
||||
record_launched() {
|
||||
local kind=$1 pid=$2
|
||||
capture_and_publish() {
|
||||
local kind=$1 pid=$2 start pgid
|
||||
for _ in {1..50}; do
|
||||
if demo_record_process "$ROOT" "$kind" "$pid"; then return 0; fi
|
||||
if demo_capture_process "$ROOT" "$kind" "$pid" start pgid; then
|
||||
if [[ "$kind" == anvil ]]; then ANVIL_START=$start; ANVIL_PGID=$pgid
|
||||
else VITE_START=$start; VITE_PGID=$pgid; fi
|
||||
demo_publish_process "$ROOT" "$kind" "$pid" "$start" "$pgid"
|
||||
return
|
||||
fi
|
||||
demo_pid_is_running "$pid" || break
|
||||
sleep 0.02
|
||||
done
|
||||
printf 'Could not prove identity for launched %s PID %s; stopping without targeting an unverified PID.\n' "$kind" "$pid" >&2
|
||||
printf 'Could not prove identity for launched %s PID %s; no signal will be guessed.\n' "$kind" "$pid" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -37,9 +52,9 @@ bash tools/reset-local.sh
|
||||
bash tools/doctor.sh
|
||||
install -d -m 0700 "$ROOT/.demo"
|
||||
|
||||
setsid anvil --host 127.0.0.1 --port 8545 --chain-id 31337 --mnemonic "$ANVIL_TEST_PHRASE" >"$ROOT/.demo/anvil.log" 2>&1 &
|
||||
setsid anvil --host 127.0.0.1 --port 8545 --chain-id 31337 --mnemonic "${ANVIL_DEV_WORDS[*]}" >"$ROOT/.demo/anvil.log" 2>&1 &
|
||||
ANVIL_PID=$!
|
||||
record_launched anvil "$ANVIL_PID"
|
||||
capture_and_publish anvil "$ANVIL_PID"
|
||||
for _ in {1..100}; do
|
||||
if [[ $(cast chain-id --rpc-url http://127.0.0.1:8545 2>/dev/null || true) == 31337 ]]; then ANVIL_READY=1; break; fi
|
||||
demo_pid_is_running "$ANVIL_PID" || break
|
||||
@@ -57,7 +72,7 @@ node tools/publish-web-manifest.mjs
|
||||
|
||||
setsid "$ROOT/web/node_modules/.bin/vite" web --host 127.0.0.1 --port 5173 >"$ROOT/.demo/vite.log" 2>&1 &
|
||||
VITE_PID=$!
|
||||
record_launched vite "$VITE_PID"
|
||||
capture_and_publish vite "$VITE_PID"
|
||||
for _ in {1..100}; do
|
||||
if curl --fail --silent --output /dev/null http://127.0.0.1:5173/; then VITE_READY=1; break; fi
|
||||
demo_pid_is_running "$VITE_PID" || break
|
||||
|
||||
Reference in New Issue
Block a user