From 103a4d6527f7e94bce5598ce0903534f408e90c9 Mon Sep 17 00:00:00 2001 From: dheerajoruganty Date: Fri, 2 May 2025 15:47:43 +0000 Subject: [PATCH] fix: uvicorn server websocket fix --- Dockerfile | 3 ++- docker/entrypoint.sh | 2 +- registry/main.py | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7cbddf7..3b56939 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 \ DEBIAN_FRONTEND=noninteractive -# Install system dependencies: nginx, curl (for health checks in registry), procps (for ps command used in stop script), openssl (for cert generation), git (needed by uv sometimes), build-essential (for potential C extensions) +# Install system dependencies: nginx, curl (for health checks in registry), procps (for ps command used in stop script), openssl (for cert generation), git (needed by uv sometimes), build-essential (for potential C extensions), sudo (for sudo command) RUN apt-get update && apt-get install -y --no-install-recommends \ nginx \ curl \ @@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ git \ build-essential \ + sudo \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 1bf573d..29b5611 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -62,7 +62,7 @@ cd /app/registry # Use uv run to start uvicorn, ensuring it uses the correct environment # Run on 0.0.0.0 to be accessible within the container network # Use port 7860 as configured in nginx proxy_pass -uv run uvicorn main:app --host 0.0.0.0 --port 7860 & +sudo uv run uvicorn main:app --host 0.0.0.0 --port 7860 & echo "MCP Registry start command issued." # Give registry a moment to initialize and generate initial nginx config sleep 10 diff --git a/registry/main.py b/registry/main.py index 9e889c0..09c3d2b 100644 --- a/registry/main.py +++ b/registry/main.py @@ -25,6 +25,7 @@ from fastapi.templating import Jinja2Templates from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature from dotenv import load_dotenv +import subprocess # Added for nginx reload # --- MCP Client Imports --- START from mcp import ClientSession @@ -180,7 +181,26 @@ def regenerate_nginx_config(): with open(NGINX_CONFIG_PATH, 'w') as f_out: f_out.write(final_config) print("Nginx config regeneration successful.") - return True + + # --- Reload Nginx --- START + try: + print("Attempting to reload Nginx configuration...") + # Ensure nginx command is available in PATH and process has permissions + result = subprocess.run(['nginx', '-s', 'reload'], check=True, capture_output=True, text=True) + print(f"Nginx reload successful. Output:\n{result.stdout}") + # --- Reload Nginx --- END + return True # Return True only if write AND reload succeed + except FileNotFoundError: + print("ERROR: 'nginx' command not found. Cannot reload configuration.") + return False # Indicate failure if nginx command isn't found + except subprocess.CalledProcessError as e: + print(f"ERROR: Failed to reload Nginx configuration. Return code: {e.returncode}") + print(f"Stderr: {e.stderr}") + print(f"Stdout: {e.stdout}") + return False # Indicate failure on reload error + except Exception as e: # Catch other potential exceptions like permission errors + print(f"ERROR: An unexpected error occurred during Nginx reload: {e}") + return False # Indicate failure except FileNotFoundError: print(f"ERROR: Nginx template file not found at {NGINX_TEMPLATE_PATH}")