#!/bin/bash containerstart=`stat -c %Z /proc/1` curtime=`date +%s` if (( curtime-containerstart < 180 )); then while ! mongo --host "${DB_CLUSTER}" --eval "db.runCommand( { connectionStatus: 1 } )"; do echo "Waiting for ${DB_CLUSTER} to be available"; sleep 1; done echo "0" exit 0 fi curl -f 127.0.0.1:8090/login || exit 1 # Проверяем наличие файла с переменной time_to_dead if [ -f /tmp/dead ];then if (( ${curtime} > $(cat /tmp/dead) ));then kill 1;fi else # Определяем изменился ли адрес админки ping -c3 $(cat /tmp/admin_ip) if [[ $? -ne 0 ]]; then new_admin_ip=$(dig +short ${ADMIN_HOST}.${APPNET}) if [[ ${new_admin_ip} != $(cat /tmp/admin_ip) ]];then ping -c3 ${new_admin_ip} || exit 0 fi # Вычисляем адреса task'ов и сортируем их sorted=($(echo $(dig tasks.${SERVICE_NAME}.${APPNET} +short)|tr " " "\n"|sort -n)) for (( i=0; i < ${#sorted[*]}; i++ )) do [[ $(ip a | grep ${sorted[${i}]}) ]] && echo $((${i}*180+$(date +%s)+40)) > /tmp/dead done fi fi exit 0