- Add WebSocket shutdown() with client notification and graceful close - Enhance download service stop() with pending state persistence - Expand FastAPI lifespan shutdown with proper cleanup sequence - Add SQLite WAL checkpoint before database close - Update stop_server.sh to use SIGTERM with timeout fallback - Configure uvicorn timeout_graceful_shutdown=30s - Update ARCHITECTURE.md with shutdown documentation
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Startup script for the Aniworld FastAPI application.
|
|
|
|
This script starts the application with proper logging configuration
|
|
and graceful shutdown support via Ctrl+C (SIGINT) or SIGTERM.
|
|
"""
|
|
import uvicorn
|
|
|
|
from src.infrastructure.logging.uvicorn_config import get_uvicorn_log_config
|
|
|
|
if __name__ == "__main__":
|
|
# Get logging configuration
|
|
log_config = get_uvicorn_log_config()
|
|
|
|
# Run the application with logging.
|
|
# Only watch .py files in src/, explicitly exclude __pycache__.
|
|
# This prevents reload loops from .pyc compilation.
|
|
#
|
|
# Graceful shutdown:
|
|
# - Ctrl+C (SIGINT) or SIGTERM triggers graceful shutdown
|
|
# - timeout_graceful_shutdown ensures shutdown completes within 30s
|
|
# - The FastAPI lifespan handler orchestrates cleanup in proper order
|
|
uvicorn.run(
|
|
"src.server.fastapi_app:app",
|
|
host="127.0.0.1",
|
|
port=8000,
|
|
reload=True,
|
|
reload_dirs=["src"],
|
|
reload_includes=["*.py"],
|
|
reload_excludes=["*/__pycache__/*", "*.pyc"],
|
|
log_config=log_config,
|
|
timeout_graceful_shutdown=30, # Allow 30s for graceful shutdown
|
|
)
|