File size: 717 Bytes
f1b0176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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}