functionality updates

This commit is contained in:
2026-09-15 17:13:32 +06:00
parent bd7ac94e74
commit b8d3a44d22
11 changed files with 338 additions and 533 deletions

31
healthcheck.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Liveness check for the CoAP server. Exits 0 if healthy, 1 if not.
# ./healthcheck.sh quiet, for cron/systemd/monitoring
# ./healthcheck.sh -v print what it found
# Retargets with COAP_HOST / COAP_PORT.
CLIENT=${CLIENT:-$(dirname "$0")/target/release/client}
verbose=false; [[ $1 == -v ]] && verbose=true
say() { $verbose && echo "$@"; }
host=${COAP_HOST:-127.0.0.1}; port=${COAP_PORT:-5683}
[[ -x $CLIENT ]] || { echo "healthcheck: no client binary at $CLIENT (cargo build --release)"; exit 1; }
reply=$("$CLIENT" get /health 2>&1)
# A bound socket proves nothing on UDP - the round trip is the real test.
if [[ $reply != "<- 2.05 "* ]]; then
echo "UNHEALTHY: coap://$host:$port/health -> ${reply:-no reply}"
exit 1
fi
body=${reply#<- 2.05 }
if [[ $body != *'"status":"ok"'* ]]; then
echo "UNHEALTHY: unexpected body from coap://$host:$port/health -> $body"
exit 1
fi
uptime=$(sed -n 's/.*"uptime":\([0-9]*\).*/\1/p' <<<"$body")
say "HEALTHY: coap://$host:$port up ${uptime}s (code 2.05)"
exit 0