2026-07-23 18:02:24 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# Restart the investor-flow dev servers (frontend :3000 + backend :3001).
|
|
|
|
|
#
|
|
|
|
|
# WHY THIS SCRIPT EXISTS:
|
|
|
|
|
# Next/Turbopack spawns a Node worker pool to process CSS (PostCSS/Tailwind).
|
|
|
|
|
# It locates Node via the NODE environment variable. If NODE is unset/empty
|
|
|
|
|
# (e.g. a bare `nohup next dev &`), the worker spawn fails with
|
|
|
|
|
# "spawning node pooled process -> No such file or directory" and the app 500s.
|
|
|
|
|
# So we always export NODE to the real homebrew node binary below.
|
|
|
|
|
#
|
|
|
|
|
# Usage (from anywhere):
|
|
|
|
|
# bash /Users/laptran/Documents/investor-flow/restart-servers.sh
|
|
|
|
|
# # or, from the repo root:
|
|
|
|
|
# ./restart-servers.sh
|
|
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
|
|
|
|
|
# Prefer PATH node; fall back to common install locations.
|
|
|
|
|
NODE_BIN="$(command -v node 2>/dev/null || true)"
|
|
|
|
|
if [ -z "${NODE_BIN}" ] || [ ! -x "${NODE_BIN}" ]; then
|
|
|
|
|
for candidate in \
|
|
|
|
|
/Users/laptran/.local/bin/node \
|
|
|
|
|
/opt/homebrew/bin/node \
|
|
|
|
|
/usr/local/bin/node
|
|
|
|
|
do
|
|
|
|
|
if [ -x "$candidate" ]; then NODE_BIN="$candidate"; break; fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
if [ -z "${NODE_BIN}" ] || [ ! -x "${NODE_BIN}" ]; then
|
|
|
|
|
echo "ERROR: could not find a node binary on PATH or known locations." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
ROOT="/Users/laptran/Documents/investor-flow"
|
|
|
|
|
SRV="$ROOT/app/server"
|
|
|
|
|
APP="$ROOT/app"
|
|
|
|
|
BK_LOG="/tmp/iflow-backend.log"
|
|
|
|
|
NX_LOG="/tmp/iflow-next.log"
|
|
|
|
|
|
|
|
|
|
# --- stop existing servers (by listen port, not pkill -f self-match) --------
|
|
|
|
|
for p in 3000 3001; do
|
|
|
|
|
pids=$(lsof -tiTCP:$p -sTCP:LISTEN 2>/dev/null || true)
|
|
|
|
|
if [ -n "${pids:-}" ]; then kill $pids 2>/dev/null || true; fi
|
|
|
|
|
done
|
2026-08-10 13:36:26 -04:00
|
|
|
# Kill orphaned --watch parent processes: they survive the listener kill and
|
|
|
|
|
# respawn children that then fight over the ports with the fresh instances.
|
|
|
|
|
# Target only our own server commands (never pkill -f self-match).
|
|
|
|
|
pkill -f "--watch --experimental-strip-types src/index.ts" 2>/dev/null || true
|
|
|
|
|
pkill -f "next dev --port 3000" 2>/dev/null || true
|
|
|
|
|
pkill -f "node_modules/.bin/next-server" 2>/dev/null || true
|
2026-07-23 18:02:24 -04:00
|
|
|
sleep 2
|
|
|
|
|
|
|
|
|
|
NODE_DIR="$(dirname "$NODE_BIN")"
|
|
|
|
|
|
|
|
|
|
# --- backend :3001 (node --watch, re-spawns on file change) -----------------
|
|
|
|
|
( cd "$SRV" && \
|
|
|
|
|
nohup env NODE="$NODE_BIN" PATH="$NODE_DIR:$PATH" \
|
|
|
|
|
"$NODE_BIN" --watch --experimental-strip-types src/index.ts \
|
|
|
|
|
> "$BK_LOG" 2>&1 </dev/null & )
|
|
|
|
|
|
|
|
|
|
# --- frontend :3000 (Next dev; NODE must be set for Turbopack) ------------
|
|
|
|
|
( cd "$APP" && \
|
|
|
|
|
nohup env HOSTNAME=0.0.0.0 NODE="$NODE_BIN" PATH="$NODE_DIR:$PATH" \
|
|
|
|
|
"$NODE_BIN" node_modules/.bin/next dev --port 3000 \
|
|
|
|
|
> "$NX_LOG" 2>&1 </dev/null & )
|
|
|
|
|
|
|
|
|
|
echo "Restart signal sent. Waiting for servers to come up..."
|
|
|
|
|
sleep 8
|
|
|
|
|
|
|
|
|
|
echo "--- listening ports ---"
|
|
|
|
|
if lsof -iTCP:3000 -iTCP:3001 -sTCP:LISTEN -P 2>/dev/null; then
|
|
|
|
|
echo "OK: both servers up."
|
|
|
|
|
else
|
|
|
|
|
echo "WARN: not listening yet. Tail the logs:"
|
|
|
|
|
echo " backend: tail -f $BK_LOG"
|
|
|
|
|
echo " frontend: tail -f $NX_LOG"
|
|
|
|
|
fi
|
|
|
|
|
echo "--- backend health ---"
|
|
|
|
|
curl -s -o /dev/null -w " :3001 -> HTTP %{http_code}\n" http://localhost:3001/health || echo " :3001 -> down"
|