blob: 71024ccb2a8566fe48326b731837c35bf68f2edb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
|