From 5e237d0d0331694ef6a6aa5b362c8b77df3d9fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 31 May 2023 14:18:15 -0400 Subject: [PATCH] Update gunicorn to use a config file as well + Fix headers error + Small fixes --- src/ui/Dockerfile | 2 +- src/ui/gunicorn.conf.py | 23 +++++++++++++++++++++++ src/ui/main.py | 13 ++++++------- src/ui/src/Instances.py | 4 ++-- src/ui/templates/loading.html | 1 + 5 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/ui/gunicorn.conf.py diff --git a/src/ui/Dockerfile b/src/ui/Dockerfile index 4b03e8f16..1c96d3797 100755 --- a/src/ui/Dockerfile +++ b/src/ui/Dockerfile @@ -79,4 +79,4 @@ USER ui:ui HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=6 CMD /usr/share/bunkerweb/helpers/healthcheck-ui.sh ENV PYTHONPATH /usr/share/bunkerweb/deps/python -CMD ["python3", "-m", "gunicorn", "--user", "ui", "--group", "ui", "main:app", "--worker-class", "gevent", "--bind", "0.0.0.0:7000", "--graceful-timeout", "0", "--access-logfile", "-", "--error-logfile", "-"] +CMD ["python3", "-m", "gunicorn", "--config", "/usr/share/bunkerweb/ui/gunicorn.conf.py", "--bind", "0.0.0.0:7000"] diff --git a/src/ui/gunicorn.conf.py b/src/ui/gunicorn.conf.py new file mode 100644 index 000000000..6a48c89a6 --- /dev/null +++ b/src/ui/gunicorn.conf.py @@ -0,0 +1,23 @@ +from os import sep +from os.path import join + +wsgi_app = "main:app" +proc_name = "bunkerweb-ui" +accesslog = "-" +access_log_format = ( + '%({x-forwarded-for}i)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' +) +errorlog = "-" +preload_app = True +pidfile = join(sep, "var", "tmp", "bunkerweb", "ui.pid") +user = "ui" +group = "ui" +secure_scheme_headers = { + "X-FORWARDED-PROTOCOL": "https", + "X-FORWARDED-PROTO": "https", + "X-FORWARDED-SSL": "on", +} +forwarded_allow_ips = "*" +proxy_allow_ips = "*" +worker_class = "gevent" +graceful_timeout = 0 diff --git a/src/ui/main.py b/src/ui/main.py index 2c1c5d117..aeb347a97 100755 --- a/src/ui/main.py +++ b/src/ui/main.py @@ -18,6 +18,10 @@ for deps_path in [ if deps_path not in sys_path: sys_path.append(deps_path) +from gevent import monkey + +monkey.patch_all() + from bs4 import BeautifulSoup from copy import deepcopy from datetime import datetime, timedelta, timezone @@ -93,8 +97,8 @@ def stop_gunicorn(): def stop(status, stop=True): - Path(sep, "var", "tmp", "bunkerweb", "ui.pid").unlink(exist_ok=True) - Path(sep, "var", "tmp", "bunkerweb", "ui.healthy").unlink(exist_ok=True) + Path(sep, "var", "tmp", "bunkerweb", "ui.pid").unlink(missing_ok=True) + Path(sep, "var", "tmp", "bunkerweb", "ui.healthy").unlink(missing_ok=True) if stop is True: stop_gunicorn() _exit(status) @@ -110,11 +114,6 @@ signal(SIGINT, handle_stop) signal(SIGTERM, handle_stop) sbin_nginx_path = Path(sep, "usr", "sbin", "nginx") -pid_file = Path(sep, "var", "tmp", "bunkerweb", "ui.pid") -if not pid_file.is_file(): - pid_file.write_text(str(getpid())) - -del pid_file # Flask app app = Flask( diff --git a/src/ui/src/Instances.py b/src/ui/src/Instances.py index bdbcdedbf..c60020196 100644 --- a/src/ui/src/Instances.py +++ b/src/ui/src/Instances.py @@ -135,7 +135,7 @@ class Instances: instances.append( Instance( - instance._id, + instance.id, instance.name, instance.name, "container", @@ -183,7 +183,7 @@ class Instances: instances.append( Instance( - instance._id, + instance.id, instance.name, instance.name, "service", diff --git a/src/ui/templates/loading.html b/src/ui/templates/loading.html index 4fb90dbcb..10c496252 100644 --- a/src/ui/templates/loading.html +++ b/src/ui/templates/loading.html @@ -40,6 +40,7 @@ logoEl.classList.toggle("scale-105"); }, 300); const reloading = setInterval(check_reloading, 2000); + check_reloading(); async function check_reloading() { const controller = new AbortController();