supervisord
This commit is contained in:
@@ -2,8 +2,10 @@ 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 # Updated import
|
||||||
|
|
||||||
|
|
||||||
edit_bp = Blueprint('edit', __name__)
|
edit_bp = Blueprint('edit', __name__)
|
||||||
|
|
||||||
|
|
||||||
@edit_bp.route('/edit', methods=['GET', 'POST'])
|
@edit_bp.route('/edit', methods=['GET', 'POST'])
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def edit_haproxy_config():
|
def edit_haproxy_config():
|
||||||
@@ -35,13 +37,35 @@ def edit_haproxy_config():
|
|||||||
error_message = check_result.stderr
|
error_message = check_result.stderr
|
||||||
check_output += f"\n\nError occurred:\n{error_message}"
|
check_output += f"\n\nError occurred:\n{error_message}"
|
||||||
else:
|
else:
|
||||||
# If no error, run systemctl restart haproxy to reload HAProxy
|
# Try to reload HAProxy - support both Docker (supervisor) and systemd
|
||||||
reload_result = subprocess.run(['systemctl', 'restart', 'haproxy'], capture_output=True, text=True)
|
reload_success = False
|
||||||
check_output += f"\n\nHAProxy Restart Output:\n{reload_result.stdout}"
|
reload_output = ""
|
||||||
|
|
||||||
# Also add stderr if there are any warnings or errors during restart
|
# Try supervisor first (Docker)
|
||||||
if reload_result.stderr:
|
try:
|
||||||
check_output += f"\nRestart Stderr:\n{reload_result.stderr}"
|
supervisor_result = subprocess.run(['supervisorctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=5)
|
||||||
|
if supervisor_result.returncode == 0:
|
||||||
|
reload_output = f"\n\n✓ HAProxy Restarted via Supervisor:\n{supervisor_result.stdout}"
|
||||||
|
reload_success = True
|
||||||
|
except Exception as e:
|
||||||
|
reload_output += f"\nSupervisor restart failed: {e}"
|
||||||
|
|
||||||
|
# If supervisor failed, try systemctl (Linux)
|
||||||
|
if not reload_success:
|
||||||
|
try:
|
||||||
|
systemctl_result = subprocess.run(['systemctl', 'restart', 'haproxy'], capture_output=True, text=True, timeout=5)
|
||||||
|
if systemctl_result.returncode == 0:
|
||||||
|
reload_output = f"\n\n✓ HAProxy Restarted via Systemctl:\n{systemctl_result.stdout}"
|
||||||
|
reload_success = True
|
||||||
|
else:
|
||||||
|
reload_output += f"\nSystemctl restart error: {systemctl_result.stderr}"
|
||||||
|
except Exception as e:
|
||||||
|
reload_output += f"\nSystemctl restart failed: {e}"
|
||||||
|
|
||||||
|
if reload_success:
|
||||||
|
check_output += reload_output
|
||||||
|
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."
|
||||||
|
|
||||||
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