Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scripts/dockermap-fixture-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ write_state() {

cleanup_on_error() {
local exit_code=$?
trap - EXIT INT TERM
if [[ "$exit_code" -ne 0 ]]; then
echo "[dockermap-fixture] setup failed; attempting cleanup" >&2
"$ROOT_DIR/scripts/dockermap-fixture-down.sh" --state-file "$STATE_FILE" >/dev/null 2>&1 || true
fi
exit "$exit_code"
}
trap cleanup_on_error EXIT
trap cleanup_on_error EXIT INT TERM

curl_json() {
local url="$1"
Expand Down Expand Up @@ -397,7 +398,7 @@ echo "[dockermap-fixture] starting unlabeled control container $CONTROL_CONTAINE
"${DOCKER_CMD[@]}" run -d --name "$CONTROL_CONTAINER" busybox:1.36.1 sh -c 'while true; do sleep 60; done' >/dev/null

echo "[dockermap-fixture] building daemon binary"
cargo build --manifest-path "$ROOT_DIR/crates/Cargo.toml" -p dockermap-daemon >/dev/null
CARGO_INCREMENTAL="${CARGO_INCREMENTAL:-0}" cargo build --manifest-path "$ROOT_DIR/crates/Cargo.toml" -p dockermap-daemon 2>&1 | tee "$LOG_DIR/daemon-build.log"

echo "[dockermap-fixture] starting Rust daemon on $DAEMON_URL"
PATH="$BIN_DIR:$PATH" \
Expand Down
56 changes: 49 additions & 7 deletions scripts/run-dev-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,65 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"

PIDS=()

kill_tree() {
local pid="$1"
[[ -n "$pid" ]] || return 0
if ! kill -0 "$pid" >/dev/null 2>&1; then
return 0
fi

local children=()
local child
if command -v pgrep >/dev/null 2>&1; then
while IFS= read -r child; do
[[ -n "$child" ]] && children+=("$child")
done < <(pgrep -P "$pid" 2>/dev/null || true)
fi

if ((${#children[@]} > 0)); then
for child in "${children[@]}"; do
kill_tree "$child"
done
fi

kill "$pid" >/dev/null 2>&1 || true
}

cleanup() {
local pids
mapfile -t pids < <(jobs -pr || true)
if ((${#pids[@]} > 0)); then
kill "${pids[@]}" >/dev/null 2>&1 || true
local exit_code=$?
local pid
trap - EXIT INT TERM

if ((${#PIDS[@]} > 0)); then
echo
echo "[dockermap] stopping dev stack"
for pid in "${PIDS[@]}"; do
kill_tree "$pid"
done
for pid in "${PIDS[@]}"; do
wait "$pid" >/dev/null 2>&1 || true
done
fi

exit "$exit_code"
}

trap cleanup EXIT INT TERM

start_background() {
"$@" &
PIDS+=("$!")
}

echo "[dockermap] starting rust daemon on http://127.0.0.1:4100"
cargo run -p dockermap-daemon --manifest-path crates/Cargo.toml &
start_background env CARGO_INCREMENTAL="${CARGO_INCREMENTAL:-0}" cargo run -p dockermap-daemon --manifest-path crates/Cargo.toml

echo "[dockermap] starting node api on http://127.0.0.1:4000"
npm run dev:api &
start_background npm run dev:api

echo "[dockermap] starting react web on http://127.0.0.1:3233"
npm --workspace @dockermap/web run dev -- --host 127.0.0.1 &
start_background npm --workspace @dockermap/web run dev -- --host 127.0.0.1 --port 3233 --strictPort

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Tear down the stack on strict-port failure

When port 3233 is already occupied, Vite's --strictPort exits immediately, but this script still reaches the final no-argument wait; help wait says that form waits for all children and returns zero, so the daemon/API keep running and the dev-stack command hangs instead of reporting the web startup failure and cleaning up. Please supervise child exits here (for example, wait for any tracked PID to fail and then run cleanup) so strict-port startup errors actually stop the stack.

Useful? React with 👍 / 👎.


wait
Loading