-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·64 lines (56 loc) · 1.73 KB
/
start.sh
File metadata and controls
executable file
·64 lines (56 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PID_FILE="$SCRIPT_DIR/.server.pid"
LOG_FILE="$SCRIPT_DIR/.server.log"
PORT="${PORT:-3001}"
cd "$SCRIPT_DIR"
# --- Stop anything already on the port (PID file or not) ---
EXISTING_PIDS="$(fuser "${PORT}/tcp" 2>/dev/null || true)"
if [[ -n "$EXISTING_PIDS" ]]; then
echo "Port $PORT is in use — stopping existing process(es): $EXISTING_PIDS"
for pid in $EXISTING_PIDS; do
kill "$pid" 2>/dev/null || true
done
# Wait up to 3 s for the port to free
for i in $(seq 1 6); do
sleep 0.5
STILL="$(fuser "${PORT}/tcp" 2>/dev/null || true)"
[[ -z "$STILL" ]] && break
done
fi
rm -f "$PID_FILE"
# --- Activate Python venv ---
if [[ -f "$SCRIPT_DIR/.venv/bin/activate" ]]; then
source "$SCRIPT_DIR/.venv/bin/activate"
else
echo "Warning: .venv not found — using system Python."
fi
# --- Load .env for health-check credentials ---
AUTH_USER="${AUTH_USER:-emtester}"
AUTH_PASS="${AUTH_PASS:-supress232}"
if [[ -f "$SCRIPT_DIR/.env" ]]; then
while IFS='=' read -r key val; do
[[ "$key" =~ ^[A-Z_]+$ ]] && export "$key"="$val"
done < "$SCRIPT_DIR/.env"
fi
# --- Start server ---
nohup npm run dev > "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
SERVER_PID="$(cat "$PID_FILE")"
# --- Wait for it to be ready (up to 20 s) ---
echo -n "Starting STT Benchmark server"
for i in $(seq 1 40); do
sleep 0.5
if curl -sf -u "${AUTH_USER}:${AUTH_PASS}" "http://localhost:${PORT}/models" > /dev/null 2>&1; then
echo ""
echo "Server is up — http://localhost:${PORT} (PID $SERVER_PID)"
echo "Logs: $LOG_FILE"
exit 0
fi
echo -n "."
done
echo ""
echo "Server did not respond within 20 s. Check logs:"
echo " tail -f $LOG_FILE"
exit 1