initial codes

This commit is contained in:
2025-10-28 05:31:25 +02:00
parent 96aea02b0c
commit 34d32ec5cb
7 changed files with 472 additions and 0 deletions

32
files/healthcheck.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
# Simple TCP healthcheck against the first server in NATS_SERVERS
# Accepts schemes nats:// or tls://
first_server=$(awk '{print $1}' <<< "${NATS_SERVERS:-}")
if [[ -z "${first_server}" ]]; then
echo "NATS_SERVERS not set" >&2
exit 1
fi
# Extract host and port
scheme="${first_server%%://*}"
rest="${first_server#*://}"
host="${rest%:*}"
port="${rest##*:}"
# If rest still contains '/', strip path
host="${host%%/*}"
port="${port%%/*}"
: "${port:=4222}"
# Try TCP connect (bash /dev/tcp)
timeout 3 bash -c "cat < /dev/null > /dev/tcp/${host}/${port}" 2>/dev/null || {
echo "Cannot connect to ${host}:${port}" >&2
exit 1
}
# Optionally add more checks later (e.g., NATS /varz on 8222)
exit 0