master
AdityaAngajala Publish 0.3.0 6d39e2e 2mo ago
#!/bin/bash
set -u

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PORT="${CIRCUIT_PORT:-8124}"
LOG_FILE="/tmp/circuit-generator-codex-serve.log"

if curl -fsS --max-time 2 "http://127.0.0.1:${PORT}/health" >/dev/null 2>&1; then
  echo "[circuit-generator-codex] already running on port ${PORT}"
  exit 0
fi

cd "$SCRIPT_DIR"
nohup /usr/bin/node server.js >>"$LOG_FILE" 2>&1 &
SERVER_PID=$!

for _ in 1 2 3 4 5; do
  if curl -fsS --max-time 2 "http://127.0.0.1:${PORT}/health" >/dev/null 2>&1; then
    echo "[circuit-generator-codex] started PID ${SERVER_PID} on port ${PORT}"
    exit 0
  fi
  sleep 1
done

echo "[circuit-generator-codex] failed to start; see ${LOG_FILE}" >&2
exit 1