- Add deployment/linux/ with deploy.sh for deploying from Claude-Agent LXC to Windows server - Add ServerLogsView.vue for viewing server logs from frontend - Add shared/routes/system.py for system health endpoints - Update CLAUDE.md with quick deploy instructions - Improve Windows deployment scripts (ROA2WEB-Console.ps1) - Fix OCR service validation and worker pool improvements - Update environment config examples - Various script permission and startup fixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
2.1 KiB
Bash
Executable File
56 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Wrapper script that auto-restarts uvicorn on crash
|
|
# Usage: ./run-with-restart.sh [port] [log_file]
|
|
|
|
# Get script directory and activate venv
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/venv/bin/activate"
|
|
|
|
PORT=${1:-8000}
|
|
LOG_FILE=${2:-/tmp/unified_backend.log}
|
|
MAX_RESTARTS=10
|
|
RESTART_COUNT=0
|
|
RESTART_DELAY=3
|
|
|
|
echo "[Backend Runner] Starting uvicorn with auto-restart (max $MAX_RESTARTS restarts)" | tee -a "$LOG_FILE"
|
|
echo "[Backend Runner] Port: $PORT, Log: $LOG_FILE" | tee -a "$LOG_FILE"
|
|
|
|
while [ $RESTART_COUNT -lt $MAX_RESTARTS ]; do
|
|
START_TIME=$(date +%s)
|
|
echo "" | tee -a "$LOG_FILE"
|
|
echo "[Backend Runner] $(date '+%Y-%m-%d %H:%M:%S') - Starting uvicorn (attempt $((RESTART_COUNT + 1))/$MAX_RESTARTS)..." | tee -a "$LOG_FILE"
|
|
|
|
# Run uvicorn - it will exit on crash (OOM, etc.)
|
|
uvicorn main:app --host 0.0.0.0 --port "$PORT" 2>&1 | tee -a "$LOG_FILE"
|
|
EXIT_CODE=$?
|
|
|
|
END_TIME=$(date +%s)
|
|
RUNTIME=$((END_TIME - START_TIME))
|
|
|
|
echo "[Backend Runner] $(date '+%Y-%m-%d %H:%M:%S') - uvicorn exited with code $EXIT_CODE after ${RUNTIME}s" | tee -a "$LOG_FILE"
|
|
|
|
# If it ran for more than 60 seconds, reset restart counter (was stable)
|
|
if [ $RUNTIME -gt 60 ]; then
|
|
RESTART_COUNT=0
|
|
echo "[Backend Runner] Process was stable (>${RUNTIME}s), resetting restart counter" | tee -a "$LOG_FILE"
|
|
else
|
|
RESTART_COUNT=$((RESTART_COUNT + 1))
|
|
echo "[Backend Runner] Quick crash detected, restart count: $RESTART_COUNT/$MAX_RESTARTS" | tee -a "$LOG_FILE"
|
|
fi
|
|
|
|
# Exit if user sent SIGINT (Ctrl+C) or SIGTERM
|
|
if [ $EXIT_CODE -eq 130 ] || [ $EXIT_CODE -eq 143 ]; then
|
|
echo "[Backend Runner] Received termination signal, exiting..." | tee -a "$LOG_FILE"
|
|
exit 0
|
|
fi
|
|
|
|
# Wait before restart
|
|
if [ $RESTART_COUNT -lt $MAX_RESTARTS ]; then
|
|
echo "[Backend Runner] Restarting in ${RESTART_DELAY}s..." | tee -a "$LOG_FILE"
|
|
sleep $RESTART_DELAY
|
|
fi
|
|
done
|
|
|
|
echo "[Backend Runner] Max restarts ($MAX_RESTARTS) reached. Giving up." | tee -a "$LOG_FILE"
|
|
exit 1
|