From 64d57407e07b3ead74c9efe007ddd1da420334b8 Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Mon, 20 Jan 2025 19:32:16 +0300 Subject: [PATCH] Refactor grpc-balancer to use Gunicorn and update playbook.yml for deployment - Replaced the SSL server implementation in grpc-balancer.py with Gunicorn for improved performance and scalability. - Updated playbook.yml to use Gunicorn for starting the grpc-balancer service, including SSL certificate configuration. - Removed the waitress dependency in favor of Gunicorn, streamlining the application setup. --- grpc-balancer.py | 9 +-------- playbook.yml | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/grpc-balancer.py b/grpc-balancer.py index f0ee533..e375bb0 100644 --- a/grpc-balancer.py +++ b/grpc-balancer.py @@ -318,11 +318,4 @@ if __name__ == '__main__': upload_thread = threading.Thread(target=upload_stats_to_grist, daemon=True, args=(grist_callback,)) upload_thread.start() - from waitress import serve - import ssl - - ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) - ssl_context.load_cert_chain('/root/node/cert.pem', '/root/node/key.pem') - - logging.info(f"Starting SSL server on port {PORT}") - serve(app, host='0.0.0.0', port=PORT, threads=MAX_WORKERS, connection_limit=1000, _ssl_context=ssl_context) + app.run(host='0.0.0.0', port=PORT) diff --git a/playbook.yml b/playbook.yml index b58082c..5e82a0f 100644 --- a/playbook.yml +++ b/playbook.yml @@ -200,7 +200,7 @@ - grist-api - flask - requests - - waitress + - gunicorn extra_args: --break-system-packages - name: Create SSL certificate for grpcbalancer @@ -229,7 +229,7 @@ Type=simple User=root WorkingDirectory={{ ansible_env.HOME }}/node - ExecStart=/usr/bin/python3 {{ ansible_env.HOME }}/node/grpc-balancer.py + ExecStart=/usr/local/bin/gunicorn --certfile=/root/node/cert.pem --keyfile=/root/node/key.pem -b 0.0.0.0:5000 grpc-balancer:app Restart=always RestartSec=2