Repository Public
1#!/usr/bin/env bash2# =============================================================================3# SP BOUCHER | INFRASTRUCTURE & AUTOMATION4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : UQO Éval — Le Grand Défi Immobilier8# File : scripts/healthcheck.sh9# Module : scripts10# Repository : https://git.spboucher.ai/uqo-eval-jeux11# Project Website : https://jeux.uqo-eval.app12# Created : 2026-11-2513# Last Modified : 2026-11-2514#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Technical Contact: dev@spboucher.ai24# Security/Admin : admin@spboucher.ai25#26# Copyright (c) 202627# Simon-Pierre Boucher28# All rights reserved where applicable. This file is governed by the29# applicable project license, copyright notices and relevant law.30# Existing third-party rights and notices remain unaffected.31#32# License : None specified (no license file in this repository)33#34# Do not embed credentials, private keys, access tokens,35# certificates or confidential personal information.36#37# =============================================================================38# END OF SP BOUCHER SOURCE HEADER39# =============================================================================4041#42# UQO ÉVAL — Le Grand Défi Immobilier · vérification de l'état du serveur.43#44# Interroge GET /api/v1/health, qui teste aussi la connexion à PostgreSQL.45#46# Usage :47# scripts/healthcheck.sh [URL]48#49# URL défaut : $HEALTH_URL, sinon http://127.0.0.1:${PORT:-8080}/api/v1/health50#51# Variables : HEALTH_URL, PORT, HEALTH_TIMEOUT (secondes, défaut 5).52#53# Codes de sortie :54# 0 le serveur répond et se déclare sain ({"status":"ok"})55# 1 le serveur répond mais se déclare dégradé (HTTP 503, base injoignable) ou répond autre chose56# 2 le serveur ne répond pas (connexion refusée, délai dépassé) ou curl est absent5758set -euo pipefail5960URL="${1:-${HEALTH_URL:-http://127.0.0.1:${PORT:-8080}/api/v1/health}}"61TIMEOUT="${HEALTH_TIMEOUT:-5}"6263command -v curl >/dev/null 2>&1 || { echo "ERREUR : curl est introuvable dans le PATH" >&2; exit 2; }6465BODY="$(mktemp "${TMPDIR:-/tmp}/uqo-jeux-health.XXXXXX")"66trap 'rm -f "$BODY"' EXIT6768if ! CODE="$(curl --silent --show-error --max-time "$TIMEOUT" --output "$BODY" --write-out '%{http_code}' "$URL")"; then69 echo "INJOIGNABLE : $URL" >&270 exit 271fi7273CONTENT="$(tr -d '\n' < "$BODY")"74if [ "$CODE" = "200" ] && printf '%s' "$CONTENT" | grep -Eq '"status"[[:space:]]*:[[:space:]]*"ok"'; then75 echo "OK : $CONTENT"76 exit 077fi7879echo "DÉGRADÉ (HTTP $CODE) : $CONTENT" >&280exit 181