From 1df58758b581f9f805fa420744052f89eba60227 Mon Sep 17 00:00:00 2001 From: jknapp Date: Thu, 20 Feb 2025 17:00:28 -0800 Subject: [PATCH] Make haproxy start with the script --- haproxy_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/haproxy_manager.py b/haproxy_manager.py index 8d1fcd9..d890ed7 100644 --- a/haproxy_manager.py +++ b/haproxy_manager.py @@ -351,7 +351,6 @@ def generate_config(): # Check HAProxy Configuration, and reload if it works with open(temp_config_path, 'w') as f: f.write(config_content) - result = subprocess.run(['haproxy', '-c', '-f', temp_config_path], capture_output=True) if result.returncode == 0: print("HAProxy configuration check passed") @@ -375,8 +374,23 @@ def generate_config(): traceback.print_exc() raise +def start_haproxy(): + if not is_process_running('haproxy'): + try: + result = subprocess.run( + ['haproxy', '-W', '-S', '/tmp/haproxy-cli,level,admin', '-f', HAPROXY_CONFIG_PATH], + check=True, + capture_output=True, + text=True + ) + print("HAProxy started successfully") + except subprocess.CalledProcessError as e: + print(f"Failed to start HAProxy: {e.stdout}\n{e.stderr}") + raise + if __name__ == '__main__': init_db() certbot_register() generate_self_signed_cert(SSL_CERTS_DIR) + app.run(host='0.0.0.0', port=8000)