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