#!/bin/bash

source $LEXI_WSGI_ENV_FILE

httpcode=`wget "http://$LOCAL_SERVER/system-webportal/sync-disaster-recovery-data" --auth-no-challenge  --user=$LEXI_WSGI_USERNAME --password=$LEXI_WSGI_PASSWORD --server-response --spider --quiet "${url}" 2>&1 | awk 'NR==1{print $2}'`

# If 200, then OK and don't try again
# If 400, then sync in progress and don't try again
# Otherwise, especially if 503 Unavailable (will happen when lexi_wsgi is starting up) exit with error and try again
if (( $httpcode != 200 )) && (( $httpcode != 400 )); then
    exit 2
fi
