aboutsummaryrefslogtreecommitdiff
path: root/mod/lorea-status/bin/lorea_refresh_status
diff options
context:
space:
mode:
Diffstat (limited to 'mod/lorea-status/bin/lorea_refresh_status')
-rwxr-xr-xmod/lorea-status/bin/lorea_refresh_status43
1 files changed, 43 insertions, 0 deletions
diff --git a/mod/lorea-status/bin/lorea_refresh_status b/mod/lorea-status/bin/lorea_refresh_status
new file mode 100755
index 000000000..bce60dc30
--- /dev/null
+++ b/mod/lorea-status/bin/lorea_refresh_status
@@ -0,0 +1,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