aboutsummaryrefslogtreecommitdiff
path: root/mod/lorea-status/bin/lorea_refresh_status
blob: bce60dc307bf687b188671a8fd5d0f99b2915699 (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
42
43
#!/bin/zsh
#
## Check if hosts are up and running

typeset -A SEEDS
typeset -a STATUS

if [ ! -f /etc/default/lorea-status ] ; then
	echo "Missing /etc/default/lorea-status configuration file. Aborted."
	exit 1
fi
source /etc/default/lorea-status

for s in ${(k)SEEDS} ; do
#	echo "$s => ${SEEDS[$s]}"
	ping -c 1 -W 3 ${SEEDS[$s]} &>/dev/null
	if (( $? )) ; then
		STATUS+="{\"host\":\"$s\",\"ping\":0,\"running\":-1}"
	else
		# Host is up, check service
		echo -n "ping... "
#		pong=$(/usr/bin/wget -q -T 3 -O- https://$s/.ping)
# wget does not support SNI?
		pong=$(/usr/bin/wget --no-check-certificate -q -T 3 -O- https://$s/.ping)
		echo $pong
		if [[ "pong $s" == "$pong" ]] ; then
			STATUS+="{\"host\":\"$s\",\"ping\":1,\"running\":1}"
		else
			STATUS+="{\"host\":\"$s\",\"ping\":1,\"running\":0}"
		fi
	fi
done
# join array elements with a comma
OLD_IFS=$IFS
IFS=,
STATUS="{\"seeds\":${#SEEDS},\"list\":[${STATUS}]}"
IFS=$OLD_IFS

setopt CLOBBER
pushd /var/www/status.lorea.org/pub
echo "$STATUS" > status.json.new
mv status.json.new status.json
popd