(feature): docker health checks (#12124)

* Add Docker container health checks

* Use invoke tasks for Docker container health checks

Updates server and worker healthchecks to use invoke server-health
and invoke worker-health as requested in #12124 review.

Refs #12124

* Added HTTP host check to server health check

* Add health-check endpoint for Caddyfile

* Simplify health check for Caddy

* Remove test file

---------

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
Co-authored-by: DESKTOP-691E36A\Administrator <br198064@gmail.com>
Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
getpwnam
2026-08-31 16:46:46 +10:00
committed by GitHub
co-authored by Oliver DESKTOP-691E36A\Administrator Matthias Mair
parent 02da01dfec
commit 773ed4eb3a
3 changed files with 76 additions and 6 deletions
+20 -2
View File
@@ -1666,15 +1666,33 @@ def server_health(c, address: str = 'http://localhost:8000', timeout: int = 5):
"""Check if the web server is healthy by requesting /api/system/health/.
Exits 0 on HTTP 200, 1 otherwise.
No Django startup required.
Django startup only required when when INVENTREE_SITE_URL is not set
and no docker/devcontainer/pkg-installer env vars are set. Django exceptions
caught and logged as warnings, but do not cause the health check to fail.
"""
import urllib.error
import urllib.parse
import urllib.request
from src.backend.InvenTree.InvenTree.config import ( # type: ignore[import]
get_setting,
)
url = f'{address.rstrip("/")}/api/system/health/'
site_url = None
try:
with urllib.request.urlopen(url, timeout=timeout) as response:
site_url = get_setting('INVENTREE_SITE_URL', 'site_url', None)
except (Exception, SystemExit) as exc:
warning(f'Could not determine configured site URL: {exc}')
request = urllib.request.Request(url)
if site_url and (hostname := urllib.parse.urlparse(site_url).hostname):
request.add_header('Host', hostname)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
if response.status == 200:
success(f'Server is healthy ({url})')
return