small-hackathon-trainer / scripts /reset_server.sh
Lucas
Build training coach MVP
f1b0176
Raw
History Blame Contribute Delete
717 Bytes
#!/usr/bin/env bash
set -euo pipefail
PORT="${PORT:-7860}"
APP_COMMAND="${APP_COMMAND:-.venv/bin/python app.py}"
echo "Resetting Gradio server on port ${PORT}..."
PIDS="$(lsof -tiTCP:"${PORT}" -sTCP:LISTEN || true)"
if [[ -n "${PIDS}" ]]; then
echo "Stopping existing server process(es): ${PIDS}"
kill ${PIDS}
for _ in {1..30}; do
if ! lsof -tiTCP:"${PORT}" -sTCP:LISTEN >/dev/null 2>&1; then
break
fi
sleep 0.2
done
if lsof -tiTCP:"${PORT}" -sTCP:LISTEN >/dev/null 2>&1; then
echo "Port ${PORT} is still busy after stopping existing process(es)." >&2
exit 1
fi
else
echo "No existing server found on port ${PORT}."
fi
echo "Starting: ${APP_COMMAND}"
exec ${APP_COMMAND}