healthcheck.sh 1.1 KB

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