Skip to content

Commit c130ef5

Browse files
committed
chore(make): clean make up / make down output
Three fixes for the noisy shutdown surfaced after wiring web into make up: - start.sh: replace `sh -c 'cd web && pnpm dev'` with `pnpm -C web dev`. Now WEB_PID is pnpm's PID directly; pnpm forwards SIGTERM to its child `next dev` on shutdown, so the PID-file kill is a complete shutdown for the happy path (no orphaned children for pkill to catch). - stop.sh: sleep 0.5s after the parent kill before running pkill, so the parent has time to propagate SIGTERM to children. Quiet shutdowns now stay quiet — the "(also killed leftover process...)" lines only print when the fallback was genuinely needed. - .env.example: NEXT_TELEMETRY_DISABLED=1. Next.js was spawning a detached-flush.js helper after `make down` to phone home telemetry; this prevents that. Verified: `make up` → all 3 services 200; `make down` → 3 "stopped" lines + docker compose down + zero leftover processes (no telemetry helper, no next workers).
1 parent 1a1ff03 commit c130ef5

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ SHOPLIT_API_ADDR=:8080
1919

2020
# ─── shoplit-redirect ──────────────────────────────────────────────────
2121
SHOPLIT_REDIRECT_ADDR=:8081
22+
23+
# ─── shoplit-web (Next.js) ─────────────────────────────────────────────
24+
# Disable Next.js usage telemetry so it doesn't spawn a detached-flush.js
25+
# helper after `make down`. https://nextjs.org/telemetry
26+
NEXT_TELEMETRY_DISABLED=1

scripts/start.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ done
3232
# the PID file went missing (shell crashed before stop.sh ran, etc.).
3333
pkill -f "bin/shoplit-api" 2>/dev/null || true
3434
pkill -f "bin/shoplit-redirect" 2>/dev/null || true
35+
pkill -f "pnpm.*-C.*web.*dev" 2>/dev/null || true
3536
pkill -f "node.*next/dist/bin/next" 2>/dev/null || true
3637
pkill -f "next-server" 2>/dev/null || true
3738
sleep 0.3
@@ -51,8 +52,10 @@ nohup ./bin/shoplit-redirect >"${LOGS_DIR}/redirect.log" 2>&1 &
5152
REDIRECT_PID=$!
5253
echo "$REDIRECT_PID" > "${PIDS_DIR}/redirect.pid"
5354

54-
# Next.js dev runs from web/. Subshell so the cd doesn't leak.
55-
nohup sh -c 'cd web && pnpm dev' >"${LOGS_DIR}/web.log" 2>&1 &
55+
# Use pnpm's -C flag instead of a sh wrapper so the PID we track is pnpm's
56+
# (which forwards signals to its child `next dev` on SIGTERM), not a transient
57+
# sh process that would be orphaned by `kill $WEB_PID`.
58+
nohup pnpm -C web dev >"${LOGS_DIR}/web.log" 2>&1 &
5659
WEB_PID=$!
5760
echo "$WEB_PID" > "${PIDS_DIR}/web.pid"
5861

scripts/stop.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ set -euo pipefail
77
PIDS_DIR=.pids
88
stopped_any=0
99

10+
# Phase 1: kill the tracked parent PIDs from .pids/. pnpm forwards SIGTERM to
11+
# its child `next dev`, which kills its own workers — so this should be a
12+
# complete shutdown for the happy path.
1013
for svc in api redirect web; do
1114
pidfile="${PIDS_DIR}/${svc}.pid"
1215
if [[ -f "$pidfile" ]]; then
@@ -20,23 +23,19 @@ for svc in api redirect web; do
2023
fi
2124
done
2225

23-
# Fallback: kill anything matching binary/process names
24-
if pkill -f "bin/shoplit-api" 2>/dev/null; then
25-
echo "stopped stray shoplit-api process(es) via pkill"
26-
stopped_any=1
27-
fi
28-
if pkill -f "bin/shoplit-redirect" 2>/dev/null; then
29-
echo "stopped stray shoplit-redirect process(es) via pkill"
30-
stopped_any=1
31-
fi
32-
if pkill -f "node.*next/dist/bin/next" 2>/dev/null; then
33-
echo "stopped stray next dev process(es) via pkill"
34-
stopped_any=1
35-
fi
36-
if pkill -f "next-server" 2>/dev/null; then
37-
echo "stopped stray next-server process(es) via pkill"
38-
stopped_any=1
39-
fi
26+
# Give the parent SIGTERMs a moment to propagate to children before we go
27+
# looking for leftovers — avoids noisy "stray" messages on a clean shutdown.
28+
sleep 0.5
29+
30+
# Phase 2: defensive fallback. Anything matching these names that's still
31+
# alive is a real leftover (parent died without cleaning up, PID file lost,
32+
# etc.). Only print when we actually kill something.
33+
for pattern in "bin/shoplit-api" "bin/shoplit-redirect" "pnpm.*-C.*web.*dev" "node.*next/dist/bin/next" "next-server"; do
34+
if pkill -f "$pattern" 2>/dev/null; then
35+
echo " (also killed leftover process matching: $pattern)"
36+
stopped_any=1
37+
fi
38+
done
4039

4140
if [[ $stopped_any -eq 0 ]]; then
4241
echo "(no shoplit services were running)"

0 commit comments

Comments
 (0)