#!/bin/bash containerstart=`stat -c %Z /proc/1` curtime=`date +%s` if (( curtime-containerstart < 180 )); then echo "Container start period, returning 0" exit 0 fi curl -f -H 'Host:demo.infoclinica.ru' 127.0.0.1:9000/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=$(nslookup ${ADMIN_HOST}.${APPNET}|grep Address|tail -n1|cut -d " " -f2) if [[ ${new_admin_ip} != $(cat /tmp/admin_ip) ]];then ping -c3 ${new_admin_ip} || exit 0 fi # Вычисляем адрес node node_ip=$(nslookup ${HOSTNAME}.${APPNET}|grep Address|tail -n +2|cut -d " " -f2) # Вычисляем index в названии tasks service_index=$(nslookup ${node_ip}|grep "in-addr.arpa"|cut -d " " -f3|cut -d "." -f2) # Создаем файл со временем убийства контейнера time_to_dead=$((service_index*180+curtime+20)) echo ${time_to_dead} > /tmp/dead fi fi