new options

This commit is contained in:
Mateusz Gruszczyński
2025-11-03 11:20:55 +01:00
parent 84d7139c15
commit ca39dd35ae
2 changed files with 21 additions and 14 deletions

View File

@@ -5,8 +5,8 @@ from utils.haproxy_config import update_haproxy_config, is_frontend_exist, count
main_bp = Blueprint('main', __name__) main_bp = Blueprint('main', __name__)
def reload_haproxy(): def reload_haproxy():
"""Reload HAProxy via supervisorctl"""
try: try:
result = subprocess.run( result = subprocess.run(
['/usr/sbin/haproxy', '-f', '/etc/haproxy/haproxy.cfg', '-c'], ['/usr/sbin/haproxy', '-f', '/etc/haproxy/haproxy.cfg', '-c'],
@@ -17,25 +17,29 @@ def reload_haproxy():
if result.returncode != 0: if result.returncode != 0:
print(f"[HAPROXY] Config validation failed: {result.stderr}", flush=True) print(f"[HAPROXY] Config validation failed: {result.stderr}", flush=True)
return False, "Config validation failed" return False, f"Config validation failed: {result.stderr}"
print("[HAPROXY] Config valid, attempting restart via supervisorctl...", flush=True)
result = subprocess.run( result = subprocess.run(
['/usr/bin/supervisorctl', 'restart', 'haproxy'], ['/usr/bin/supervisorctl', 'restart', 'haproxy'],
capture_output=True, capture_output=True,
text=True, text=True,
timeout=10 timeout=15
) )
if result.returncode == 0: if result.returncode == 0:
print(f"[HAPROXY] Restarted successfully via supervisorctl", flush=True) print(f"[HAPROXY] Restarted successfully via supervisorctl", flush=True)
return True, "HAProxy restarted successfully" return True, "HAProxy restarted successfully"
else: else:
print(f"[HAPROXY] Restart failed: {result.stderr}", flush=True) stderr = result.stderr or result.stdout
return False, f"Restart failed: {result.stderr}" print(f"[HAPROXY] Restart failed: {stderr}", flush=True)
return False, f"Restart failed: {stderr}"
except Exception as e: except Exception as e:
print(f"[HAPROXY] Error reloading: {e}", flush=True) print(f"[HAPROXY] Error: {e}", flush=True)
return False, f"Error: {e}" return False, f"Error: {str(e)}"
@main_bp.route('/', methods=['GET', 'POST']) @main_bp.route('/', methods=['GET', 'POST'])
@requires_auth @requires_auth

View File

@@ -5,6 +5,16 @@ loglevel=info
logfile=/var/log/supervisor/supervisord.log logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid pidfile=/var/run/supervisord.pid
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:haproxy] [program:haproxy]
command=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg command=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg
autostart=true autostart=true
@@ -28,10 +38,3 @@ priority=999
environment=FLASK_APP=/app/app.py,FLASK_ENV=production,PYTHONUNBUFFERED=1 environment=FLASK_APP=/app/app.py,FLASK_ENV=production,PYTHONUNBUFFERED=1
startsecs=10 startsecs=10
stopasgroup=true stopasgroup=true
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock