new_functions_and_fixes #1
@@ -5,36 +5,38 @@ from utils.haproxy_config import update_haproxy_config, is_frontend_exist, count
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
|
||||
import subprocess
|
||||
|
||||
def reload_haproxy():
|
||||
"""Reload HAProxy by killing it - supervisord restarts automatically"""
|
||||
try:
|
||||
# Validate config first
|
||||
result = subprocess.run(
|
||||
['/usr/sbin/haproxy', '-f', '/etc/haproxy/haproxy.cfg', '-c'],
|
||||
capture_output=True,
|
||||
['haproxy', '-c', '-V', '-f', '/etc/haproxy/haproxy.cfg'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"[HAPROXY] Config validation failed: {result.stderr}", flush=True)
|
||||
return False, f"Config validation failed: {result.stderr}"
|
||||
|
||||
print("[HAPROXY] Config valid, attempting restart via supervisorctl...", flush=True)
|
||||
return False, f"Config validation failed: {result.stdout}"
|
||||
|
||||
# Kill haproxy - supervisord will restart it automatically
|
||||
result = subprocess.run(
|
||||
['/usr/bin/supervisorctl', 'restart', 'haproxy'],
|
||||
capture_output=True,
|
||||
['pkill', '-f', 'haproxy'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
timeout=15
|
||||
timeout=10
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
print(f"[HAPROXY] Restarted successfully via supervisorctl", flush=True)
|
||||
if result.returncode == 0 or 'No such process' in result.stdout:
|
||||
print("[HAPROXY] Process killed, supervisord will restart", flush=True)
|
||||
return True, "HAProxy restarted successfully"
|
||||
else:
|
||||
stderr = result.stderr or result.stdout
|
||||
print(f"[HAPROXY] Restart failed: {stderr}", flush=True)
|
||||
return False, f"Restart failed: {stderr}"
|
||||
print(f"[HAPROXY] pkill failed: {result.stdout}", flush=True)
|
||||
return False, f"pkill failed: {result.stdout}"
|
||||
|
||||
except Exception as e:
|
||||
print(f"[HAPROXY] Error: {e}", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user