summaryrefslogtreecommitdiff
path: root/statuspage/checks/jails.sh
diff options
context:
space:
mode:
Diffstat (limited to 'statuspage/checks/jails.sh')
-rwxr-xr-xstatuspage/checks/jails.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/statuspage/checks/jails.sh b/statuspage/checks/jails.sh
new file mode 100755
index 0000000..71024cc
--- /dev/null
+++ b/statuspage/checks/jails.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# checks/jails.sh
+# Discovers every currently running jail via jls - no separate script or
+# hardcoded name/IP needed per jail. Roll a new jail and it shows up on
+# the next render with no changes here.
+#
+# Trade-off: since jls only lists running jails, a jail that's supposed
+# to exist but isn't running just doesn't appear on the page - it won't
+# show as "down". If you need to detect an unexpectedly-stopped jail,
+# that needs an explicit expected-jails list (not implemented here).
+set -eu
+
+DIR=$(dirname "$0")
+. "$DIR/../lib/common.sh"
+
+# jail_ip4 NAME
+# Prints the jail's IPv4 address, or nothing if none could be found.
+jail_ip4() {
+ ip=$(jls -j "$1" -n ip4.addr 2>/dev/null | sed -n 's/.*ip4\.addr=\([^ ]*\).*/\1/p')
+ case "$ip" in
+ ""|-|0.0.0.0) ;;
+ *) printf '%s' "$ip"; return ;;
+ esac
+ # VNET jails run their own network stack, so ip4.addr (a classic-jail
+ # restriction parameter) is usually unset. Ask the jail directly for
+ # the first non-loopback address it sees instead.
+ jexec "$1" ifconfig -f inet:cidr 2>/dev/null \
+ | awk '/inet /{split($2,a,"/"); if (a[1] !~ /^127\./) {print a[1]; exit}}'
+}
+
+jls -n name 2>/dev/null | sed -n 's/.*name=\([^ ]*\).*/\1/p' | while IFS= read -r name; do
+ [ -n "$name" ] || continue
+
+ ip=$(jail_ip4 "$name")
+ json_line "jails" "$name jail" "$ip" "ok"
+
+ if [ -n "$ip" ]; then
+ http_status=$(port_check "$ip" 80)
+ json_line "jails" " -> http :80" "" "$http_status"
+ fi
+done