|
25 | 25 | from fastapi.templating import Jinja2Templates |
26 | 26 | from itsdangerous import URLSafeTimedSerializer, SignatureExpired, BadSignature |
27 | 27 | from dotenv import load_dotenv |
| 28 | +import subprocess # Added for nginx reload |
28 | 29 |
|
29 | 30 | # --- MCP Client Imports --- START |
30 | 31 | from mcp import ClientSession |
@@ -180,7 +181,26 @@ def regenerate_nginx_config(): |
180 | 181 | with open(NGINX_CONFIG_PATH, 'w') as f_out: |
181 | 182 | f_out.write(final_config) |
182 | 183 | print("Nginx config regeneration successful.") |
183 | | - return True |
| 184 | + |
| 185 | + # --- Reload Nginx --- START |
| 186 | + try: |
| 187 | + print("Attempting to reload Nginx configuration...") |
| 188 | + # Ensure nginx command is available in PATH and process has permissions |
| 189 | + result = subprocess.run(['nginx', '-s', 'reload'], check=True, capture_output=True, text=True) |
| 190 | + print(f"Nginx reload successful. Output:\n{result.stdout}") |
| 191 | + # --- Reload Nginx --- END |
| 192 | + return True # Return True only if write AND reload succeed |
| 193 | + except FileNotFoundError: |
| 194 | + print("ERROR: 'nginx' command not found. Cannot reload configuration.") |
| 195 | + return False # Indicate failure if nginx command isn't found |
| 196 | + except subprocess.CalledProcessError as e: |
| 197 | + print(f"ERROR: Failed to reload Nginx configuration. Return code: {e.returncode}") |
| 198 | + print(f"Stderr: {e.stderr}") |
| 199 | + print(f"Stdout: {e.stdout}") |
| 200 | + return False # Indicate failure on reload error |
| 201 | + except Exception as e: # Catch other potential exceptions like permission errors |
| 202 | + print(f"ERROR: An unexpected error occurred during Nginx reload: {e}") |
| 203 | + return False # Indicate failure |
184 | 204 |
|
185 | 205 | except FileNotFoundError: |
186 | 206 | print(f"ERROR: Nginx template file not found at {NGINX_TEMPLATE_PATH}") |
|
0 commit comments