#!/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