tcpproxy/healthz.sh

43 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2023-08-07 16:53:13 +01:00
#!/bin/bash
2023-08-09 10:34:42 +01:00
respond () {
DATE="$(LC_ALL=C date -u '+%a, %d %b %Y %H:%M:%S GMT')"
printf "%s $1\r\nDate: $DATE\r\nContent-Length: 0\r\nConnection: close\r\nContent-Type: application/octet-stream\r\n\r\n" "${start_line[2]}"
}
2023-08-07 16:53:13 +01:00
read -r -a start_line
start_line[2]="${start_line[2]%$'\r'}"
case "${start_line[2]}" in
"HTTP/1.0" | "HTTP/1.1")
case "${start_line[0]}" in
"GET")
case "${start_line[1]}" in
"/healthz/startupProbe")
if pidof -q openconnect && pidof -q tcpproxy; then
2023-08-09 10:34:42 +01:00
respond "200 OK"
2023-08-07 16:53:13 +01:00
else
2023-08-09 10:34:42 +01:00
respond "503 Service Unavailable"
2023-08-07 16:53:13 +01:00
fi
;;
"/healthz/livenessProbe" | "/healthz/readinessProbe")
if pidof -q openconnect && pidof -q tcpproxy && cmp <(ncat localhost 1234 -c "/usr/bin/printf '\x30\x0c\x02\x01\x01\x60\x07\x02\x01\x03\x04\x00\x80\x00'; timeout --preserve-status 1 cat >&2" 2>&1) <(printf "\x30\x0c\x02\x01\x01\x61\x07\x0a\x01\x00\x04\x00\x04\x00"); then
2023-08-09 10:34:42 +01:00
respond "200 OK"
2023-08-07 16:53:13 +01:00
else
2023-08-09 10:34:42 +01:00
respond "503 Service Unavailable"
2023-08-07 16:53:13 +01:00
fi
;;
*)
2023-08-09 10:34:42 +01:00
respond "404 Not Found"
2023-08-07 16:53:13 +01:00
;;
esac
;;
*)
2023-08-09 10:34:42 +01:00
respond "405 Method Not Allowed"
2023-08-07 16:53:13 +01:00
;;
esac
;;
*)
echo "Unsupported protocol ${start_line[2]}"
;;
esac