Server: Remove broken PID-based logging
- is_master() doesn't work with uvicorn workers - Keeping clean logs from cache + disabled httpx debug
This commit is contained in:
+13
-30
@@ -18,12 +18,6 @@ from uvicorn.protocols.http.httptools_impl import HttpToolsProtocol
|
||||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
|
||||
# PID for logging (only master logs startup)
|
||||
MASTER_PID = os.getpid()
|
||||
|
||||
def is_master() -> bool:
|
||||
return os.getpid() == MASTER_PID
|
||||
|
||||
from pack_manager import DATA_DIR, scan_pack, get_cached_manifest, PACKS_DIR
|
||||
from models import PackMeta
|
||||
from middleware import LoggingMiddleware
|
||||
@@ -71,11 +65,10 @@ async def lifespan(app: FastAPI):
|
||||
if BLOCKLIST_CACHE_FILE.exists():
|
||||
try:
|
||||
cached_ips = set(BLOCKLIST_CACHE_FILE.read_text().strip().splitlines())
|
||||
if cached_ips and is_master():
|
||||
if cached_ips:
|
||||
logger.info(f"Loaded {len(cached_ips)} IPs from blocklist cache")
|
||||
except Exception as e:
|
||||
if is_master():
|
||||
logger.warning(f"Failed to load blocklist cache: {e}")
|
||||
logger.warning(f"Failed to load blocklist cache: {e}")
|
||||
|
||||
# If no cache, download (only one worker will do this)
|
||||
if not cached_ips:
|
||||
@@ -92,22 +85,20 @@ async def lifespan(app: FastAPI):
|
||||
cached_ips = mw.load_public_blocklists()
|
||||
if cached_ips:
|
||||
BLOCKLIST_CACHE_FILE.write_text("\n".join(cached_ips))
|
||||
if is_master():
|
||||
logger.info(f"Downloaded and saved {len(cached_ips)} IPs to blocklist cache")
|
||||
logger.info(f"Downloaded and saved {len(cached_ips)} IPs to blocklist cache")
|
||||
except BlockingIOError:
|
||||
# Another process is downloading - wait for cache
|
||||
pass
|
||||
finally:
|
||||
lock_fd.close()
|
||||
except Exception as e:
|
||||
if is_master():
|
||||
logger.warning(f"Lock error: {e}")
|
||||
logger.warning(f"Lock error: {e}")
|
||||
|
||||
# Re-read cache after download
|
||||
if BLOCKLIST_CACHE_FILE.exists() and not cached_ips:
|
||||
try:
|
||||
cached_ips = set(BLOCKLIST_CACHE_FILE.read_text().strip().splitlines())
|
||||
if cached_ips and is_master():
|
||||
if cached_ips:
|
||||
logger.info(f"Loaded {len(cached_ips)} IPs from blocklist cache (after wait)")
|
||||
except Exception:
|
||||
pass
|
||||
@@ -115,8 +106,7 @@ async def lifespan(app: FastAPI):
|
||||
all_blocked.update(cached_ips)
|
||||
|
||||
mw.set_ip_config(blocked=all_blocked)
|
||||
if is_master():
|
||||
logger.info(f"IP blocklist loaded: {len(all_blocked)} IPs")
|
||||
logger.info(f"IP blocklist loaded: {len(all_blocked)} IPs")
|
||||
|
||||
# Determine environment
|
||||
if args.test:
|
||||
@@ -126,8 +116,7 @@ async def lifespan(app: FastAPI):
|
||||
else:
|
||||
env = "production"
|
||||
|
||||
if is_master():
|
||||
logger.info(f"Starting ZernMC Launcher Server (environment: {env})")
|
||||
logger.info(f"Starting ZernMC Launcher Server (environment: {env})")
|
||||
|
||||
# Create directories if they don't exist
|
||||
BUILDS_DIR.mkdir(exist_ok=True)
|
||||
@@ -141,26 +130,21 @@ async def lifespan(app: FastAPI):
|
||||
yield
|
||||
return
|
||||
|
||||
if is_master():
|
||||
logger.info("Scanning packs on startup...")
|
||||
logger.info("Scanning packs on startup...")
|
||||
|
||||
pack_dirs = [p for p in PACKS_DIR.iterdir() if p.is_dir()]
|
||||
|
||||
if not pack_dirs:
|
||||
if is_master():
|
||||
logger.warning(f"No packs found in directory: {PACKS_DIR}")
|
||||
logger.warning(f"No packs found in directory: {PACKS_DIR}")
|
||||
else:
|
||||
for pack_dir in pack_dirs:
|
||||
try:
|
||||
meta = await scan_pack(pack_dir.name)
|
||||
if is_master():
|
||||
logger.info(f"Pack scanned successfully: {pack_dir.name} v{meta.version} ({len(meta.files)} files)")
|
||||
logger.info(f"Pack scanned successfully: {pack_dir.name} v{meta.version} ({len(meta.files)} files)")
|
||||
except Exception as e:
|
||||
if is_master():
|
||||
logger.error(f"Failed to scan pack: {pack_dir.name} - {e}", exc_info=True)
|
||||
logger.error(f"Failed to scan pack: {pack_dir.name} - {e}", exc_info=True)
|
||||
|
||||
if is_master():
|
||||
logger.info("All packs ready. Server is running.")
|
||||
logger.info("All packs ready. Server is running.")
|
||||
|
||||
# Initialize proxy client
|
||||
global proxy_client
|
||||
@@ -172,8 +156,7 @@ async def lifespan(app: FastAPI):
|
||||
if proxy_client:
|
||||
await proxy_client.aclose()
|
||||
|
||||
if is_master():
|
||||
logger.info("Server shutting down...")
|
||||
logger.info("Server shutting down...")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user