Refactor gunicorn.conf.py and main.py to use RUN_DIR instead of TMP_DIR for storing PID file

This commit is contained in:
Théophile Diot 2024-04-24 16:36:07 +02:00
parent 500012fc54
commit e865de71a2
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
2 changed files with 5 additions and 3 deletions

View file

@ -18,6 +18,7 @@ from logger import setup_logger # type: ignore
from src.User import User
TMP_DIR = Path(sep, "var", "tmp", "bunkerweb")
RUN_DIR = Path(sep, "var", "run", "bunkerweb")
MAX_WORKERS = int(getenv("MAX_WORKERS", max((cpu_count() or 1) - 1, 1)))
LOG_LEVEL = getenv("LOG_LEVEL", "info")
@ -110,10 +111,11 @@ def on_starting(server):
def when_ready(server):
TMP_DIR.joinpath("ui.pid").write_text(str(getpid()), encoding="utf-8")
RUN_DIR.mkdir(parents=True, exist_ok=True)
RUN_DIR.joinpath("ui.pid").write_text(str(getpid()), encoding="utf-8")
TMP_DIR.joinpath("ui.healthy").write_text("ok", encoding="utf-8")
def on_exit(server):
TMP_DIR.joinpath("ui.pid").unlink(missing_ok=True)
RUN_DIR.joinpath("ui.pid").unlink(missing_ok=True)
TMP_DIR.joinpath("ui.healthy").unlink(missing_ok=True)

View file

@ -73,7 +73,7 @@ def stop_gunicorn():
def stop(status, _stop=True):
TMP_DIR.joinpath("ui.pid").unlink(missing_ok=True)
Path(sep, "var", "run", "bunkerweb", "ui.pid").unlink(missing_ok=True)
TMP_DIR.joinpath("ui.healthy").unlink(missing_ok=True)
if _stop is True:
stop_gunicorn()