diff --git a/configuration/environments_scripts/reverse_proxy/files/var/www/cgi-bin/reverseProxyHealthcheck.sh b/configuration/environments_scripts/reverse_proxy/files/var/www/cgi-bin/reverseProxyHealthcheck.sh index 27f7c6c447b..98979173b6b 100755 --- a/configuration/environments_scripts/reverse_proxy/files/var/www/cgi-bin/reverseProxyHealthcheck.sh +++ b/configuration/environments_scripts/reverse_proxy/files/var/www/cgi-bin/reverseProxyHealthcheck.sh @@ -30,13 +30,13 @@ IP_REGEX="[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+$" # Extracts which IP is in production. PRODUCTION_IP=$(sed -n -e "s/^Define ${PRODUCTION_IP_NAME}\> \(.*\)$/\1/p" ${MACROS_PATH}) SUBNET_MASK_SIZE_VAR_LOCATION="/var/cache/httpd/subnetMaskSize" +SELF_IP=$( ec2-metadata --local-ipv4 | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\>") if [[ "$1" == "cleanup" ]]; then - rm -f $SUBNET_MASK_SIZE_VAR_LOCATION + rm -f ${SUBNET_MASK_SIZE_VAR_LOCATION} status "200" outputMessage "cleanup complete" exit 0 fi -SELF_IP=$( ec2-metadata --local-ipv4 | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\>") curl --silent --location --fail "http://${SELF_IP}/internal-server-status" >/dev/null if [[ "$?" -ne 0 ]]; then status "500 Reverse proxy itself is unhealthy" @@ -46,14 +46,14 @@ fi if [[ ! -e "$SUBNET_MASK_SIZE_VAR_LOCATION" ]]; then # Get subnet mask size MY_AZ=$( ec2-metadata --availability-zone | grep -o "[a-zA-Z]\+-[a-zA-Z]\+-[0-9a-z]\+\>") - aws ec2 describe-subnets | jq -r '.Subnets[] | select( .AvailabilityZone =="'"$MY_AZ"'") | select (.Tags ==null or (.Tags | any(.Key == "noInstanceDeployment") | not )) | .CidrBlock | split("/") | .[1]' > $SUBNET_MASK_SIZE_VAR_LOCATION + aws ec2 describe-subnets | jq -r '.Subnets[] | select( .AvailabilityZone =="'"$MY_AZ"'") | select (.Tags ==null or (.Tags | any(.Key == "noInstanceDeployment") | not )) | .CidrBlock | split("/") | .[1]' > $SUBNET_MASK_SIZE_VAR_LOCATION fi if [[ "$PRODUCTION_IP" == "\${${ARCHIVE_IP_NAME}}" ]] then # Check if main archive is in the same az by comparing the network portion of the archive and this instance's IP, with the same bitmask. MY_IP=$( ec2-metadata --local-ipv4 | grep -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\>") MY_IP_VALUE="$(convert_ip_to_num "$MY_IP")" - MY_AZ_MASK_SIZE=$(cat $SUBNET_MASK_SIZE_VAR_LOCATION) + MY_AZ_MASK_SIZE=$(cat $SUBNET_MASK_SIZE_VAR_LOCATION) # convert the value after the CIDR slash into a bitmask BITMASK_VALUE=0 for i in $(seq $((31 - $MY_AZ_MASK_SIZE + 1)) 31); do @@ -64,7 +64,7 @@ then ARCHIVE_IP=$(grep -m 1 "^Define ${ARCHIVE_IP_NAME}\> .*" ${MACROS_PATH} | grep -o "${IP_REGEX}") ARCHIVE_IP_VALUE=$(convert_ip_to_num "$ARCHIVE_IP") ARCHIVE_SUBNET_VALUE=$(($BITMASK_VALUE & $ARCHIVE_IP_VALUE )) #Apply the mask to the archive IP value. - if [[ "$ARCHIVE_SUBNET_VALUE" -eq "$MY_SUBNET_VALUE" ]]; then + if [[ "$ARCHIVE_SUBNET_VALUE" -eq "$MY_SUBNET_VALUE" ]]; then status "200" outputMessage "Healthy: in the same az as the archive" else