add healthchecks to ui and autoconf docker images

This commit is contained in:
bunkerity 2023-03-24 13:23:07 +01:00
parent 4f9748cc2e
commit 041142a4f3
7 changed files with 31 additions and 0 deletions

View File

@ -62,4 +62,6 @@ WORKDIR /usr/share/bunkerweb/autoconf
USER root:nginx
HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=6 CMD /usr/share/bunkerweb/helpers/healthcheck-autoconf.sh
CMD ["python3", "/usr/share/bunkerweb/autoconf/main.py"]

View File

@ -4,6 +4,7 @@ from os import _exit, getenv
from signal import SIGINT, SIGTERM, signal
from sys import exit as sys_exit, path as sys_path
from traceback import format_exc
from pathlib import Path
sys_path.extend(
(
@ -69,9 +70,14 @@ try:
_exit(1)
# Process events
Path("/var/tmp/bunkerweb/autoconf.healthy").write_text("ok")
logger.info("Processing events ...")
controller.process_events()
except:
logger.error(f"Exception while running autoconf :\n{format_exc()}")
sys_exit(1)
finally:
Path("/var/tmp/bunkerweb/autoconf.healthy").unlink(missing_ok=True)

View File

@ -0,0 +1,7 @@
#!/bin/bash
if [ ! -f /var/tmp/bunkerweb/autoconf.healthy ] ; then
exit 1
fi
exit 0

View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ ! -f /var/tmp/bunkerweb/ui.pid ] ; then
exit 1
fi
if [ ! -f /var/tmp/bunkerweb/ui.healthy ] ; then
exit 1
fi
exit 0

View File

@ -60,5 +60,7 @@ WORKDIR /usr/share/bunkerweb/ui
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", "--access-logfile=-", "--graceful-timeout=0", "--bind=0.0.0.0:7000", "--workers=1", "--threads=2", "--user", "ui", "--group", "ui", "main:app"]

View File

@ -98,6 +98,8 @@ def stop_gunicorn():
def stop(status, stop=True):
if Path("/var/tmp/bunkerweb/ui.pid").exists():
Path("/var/tmp/bunkerweb/ui.pid").unlink()
if Path("/var/tmp/bunkerweb/ui.healthy").exists():
Path("/var/tmp/bunkerweb/ui.healthy").unlink()
if stop is True:
stop_gunicorn()
_exit(status)

View File

@ -39,6 +39,7 @@ class Config:
env = self.__db.get_config()
self.__logger.info("Database is ready")
Path("/var/tmp/bunkerweb/ui.healthy").write_text("ok")
def __env_to_dict(self, filename: str) -> dict:
"""Converts the content of an env file into a dict