supervisord
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from flask import Blueprint, render_template, request
|
from flask import Blueprint, render_template, request
|
||||||
import subprocess
|
import subprocess
|
||||||
from auth.auth_middleware import requires_auth # Updated import
|
from auth.auth_middleware import requires_auth
|
||||||
|
|
||||||
|
|
||||||
edit_bp = Blueprint('edit', __name__)
|
edit_bp = Blueprint('edit', __name__)
|
||||||
@@ -41,31 +41,59 @@ def edit_haproxy_config():
|
|||||||
reload_success = False
|
reload_success = False
|
||||||
reload_output = ""
|
reload_output = ""
|
||||||
|
|
||||||
# Try supervisor first (Docker)
|
# Method 1: Supervisor with sudo (Docker)
|
||||||
try:
|
try:
|
||||||
supervisor_result = subprocess.run(['supervisorctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=5)
|
supervisor_result = subprocess.run(['sudo', 'supervisorctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=10)
|
||||||
if supervisor_result.returncode == 0:
|
if supervisor_result.returncode == 0:
|
||||||
reload_output = f"\n\n✓ HAProxy Restarted via Supervisor:\n{supervisor_result.stdout}"
|
reload_output = f"\n\n✓ HAProxy Restarted via Supervisor:\n{supervisor_result.stdout}"
|
||||||
reload_success = True
|
reload_success = True
|
||||||
|
print(f"[HAPROXY] Supervisor restart successful", flush=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
reload_output += f"\nSupervisor restart failed: {e}"
|
print(f"[HAPROXY] Supervisor restart failed: {e}", flush=True)
|
||||||
|
|
||||||
# If supervisor failed, try systemctl (Linux)
|
# Method 2: Direct supervisorctl without sudo (Docker)
|
||||||
if not reload_success:
|
if not reload_success:
|
||||||
try:
|
try:
|
||||||
systemctl_result = subprocess.run(['systemctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=5)
|
supervisor_result = subprocess.run(['supervisorctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=10)
|
||||||
|
if supervisor_result.returncode == 0:
|
||||||
|
reload_output = f"\n\n✓ HAProxy Restarted via Supervisor:\n{supervisor_result.stdout}"
|
||||||
|
reload_success = True
|
||||||
|
print(f"[HAPROXY] Supervisor restart successful", flush=True)
|
||||||
|
else:
|
||||||
|
print(f"[HAPROXY] Supervisor failed: {supervisor_result.stderr}", flush=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[HAPROXY] Supervisor failed: {e}", flush=True)
|
||||||
|
|
||||||
|
# Method 3: Systemctl with sudo (Linux)
|
||||||
|
if not reload_success:
|
||||||
|
try:
|
||||||
|
systemctl_result = subprocess.run(['sudo', 'systemctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=10)
|
||||||
if systemctl_result.returncode == 0:
|
if systemctl_result.returncode == 0:
|
||||||
reload_output = f"\n\n✓ HAProxy Restarted via Systemctl:\n{systemctl_result.stdout}"
|
reload_output = f"\n\n✓ HAProxy Restarted via Systemctl:\n{systemctl_result.stdout}"
|
||||||
reload_success = True
|
reload_success = True
|
||||||
|
print(f"[HAPROXY] Systemctl restart successful", flush=True)
|
||||||
else:
|
else:
|
||||||
reload_output += f"\nSystemctl restart error: {systemctl_result.stderr}"
|
print(f"[HAPROXY] Systemctl failed: {systemctl_result.stderr}", flush=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
reload_output += f"\nSystemctl restart failed: {e}"
|
print(f"[HAPROXY] Systemctl failed: {e}", flush=True)
|
||||||
|
|
||||||
|
# Method 4: Direct systemctl without sudo (Linux)
|
||||||
|
if not reload_success:
|
||||||
|
try:
|
||||||
|
systemctl_result = subprocess.run(['systemctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=10)
|
||||||
|
if systemctl_result.returncode == 0:
|
||||||
|
reload_output = f"\n\n✓ HAProxy Restarted via Systemctl:\n{systemctl_result.stdout}"
|
||||||
|
reload_success = True
|
||||||
|
print(f"[HAPROXY] Systemctl restart successful", flush=True)
|
||||||
|
else:
|
||||||
|
print(f"[HAPROXY] Systemctl failed: {systemctl_result.stderr}", flush=True)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[HAPROXY] Systemctl failed: {e}", flush=True)
|
||||||
|
|
||||||
if reload_success:
|
if reload_success:
|
||||||
check_output += reload_output
|
check_output += reload_output
|
||||||
else:
|
else:
|
||||||
check_output += f"\n\n⚠ Warning: Could not restart HAProxy.\nConfig is valid but reload failed.\nPlease restart manually or check supervisor/systemd status."
|
check_output += f"\n\n⚠ Warning: Could not restart HAProxy.\nConfig is valid but reload failed.\n\nTroubleshooting:\n1. Check if supervisord/systemd is running\n2. Verify haproxy program is defined in supervisor\n3. Check Docker logs: docker-compose logs\n4. Manual restart: docker-compose exec <container> supervisorctl restart haproxy"
|
||||||
|
|
||||||
return render_template('edit.html', config_content=edited_config, check_output=check_output)
|
return render_template('edit.html', config_content=edited_config, check_output=check_output)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user