Download start.sh from Text-to-Document-Generation/Docgenie-API: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/Text-to-Document-Generation/Docgenie-API/resolve/main/start.sh
- Command line
-
hf download hf://spaces/Text-to-Document-Generation/Docgenie-API/start.sh
-
curl -L -o start.sh https://huggingface.co/spaces/Text-to-Document-Generation/Docgenie-API/resolve/main/start.sh
2.2 kB
| set -e | |
| echo "π Starting DocGenie API + Worker..." | |
| echo "============================================================" | |
| echo "π§ Configuration:" | |
| echo " PORT: ${PORT:-7860}" | |
| echo " REDIS_URL: ${REDIS_URL:0:30}..." | |
| echo " ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:0:20}..." | |
| echo "============================================================" | |
| # Function to add prefix to logs | |
| prefix_logs() { | |
| local prefix=$1 | |
| while IFS= read -r line; do | |
| echo "[$prefix] $line" | |
| done | |
| } | |
| # Start API server in background with log prefix | |
| echo "π Starting FastAPI server..." | |
| uvicorn api.main:app --host 0.0.0.0 --port ${PORT:-7860} 2>&1 | prefix_logs "API" & | |
| API_PID=$! | |
| echo " PID: $API_PID" | |
| # Give API a moment to start | |
| sleep 2 | |
| # Start RQ worker in background with log prefix | |
| # Use timestamp + random number to ensure unique worker name across deployments | |
| WORKER_ID="docgenie-worker-$(date +%s)-${RANDOM}" | |
| echo "π· Starting RQ Worker..." | |
| rq worker ${RQ_QUEUE_NAME:-docgenie} --url $REDIS_URL --name "$WORKER_ID" --verbose 2>&1 | prefix_logs "WORKER" & | |
| WORKER_PID=$! | |
| echo " PID: $WORKER_PID" | |
| echo "============================================================" | |
| echo "β Both processes started successfully" | |
| echo " API: http://0.0.0.0:${PORT:-7860}" | |
| echo " Worker: Connected to Redis" | |
| echo "============================================================" | |
| # Function to handle shutdown | |
| shutdown() { | |
| echo "" | |
| echo "π Shutting down gracefully..." | |
| kill -TERM $API_PID 2>/dev/null || true | |
| kill -TERM $WORKER_PID 2>/dev/null || true | |
| wait $API_PID 2>/dev/null || true | |
| wait $WORKER_PID 2>/dev/null || true | |
| echo "β Shutdown complete" | |
| exit 0 | |
| } | |
| # Trap SIGTERM and SIGINT | |
| trap shutdown SIGTERM SIGINT | |
| # Wait for both processes - if either exits, shutdown both | |
| while kill -0 $API_PID 2>/dev/null && kill -0 $WORKER_PID 2>/dev/null; do | |
| sleep 1 | |
| done | |
| # If we get here, one process died | |
| echo "" | |
| echo "β One of the processes exited unexpectedly" | |
| if ! kill -0 $API_PID 2>/dev/null; then | |
| echo " API process died (PID: $API_PID)" | |
| fi | |
| if ! kill -0 $WORKER_PID 2>/dev/null; then | |
| echo " Worker process died (PID: $WORKER_PID)" | |
| fi | |
| shutdown | |