Browse Source

Change configs. See Redmine 114401

Владимир Томишинец 5 years ago
parent
commit
68c4bb32e6
2 changed files with 32 additions and 6 deletions
  1. 9 6
      docker-entrypoint.sh
  2. 23 0
      healthcheck.sh

+ 9 - 6
docker-entrypoint.sh

@@ -2,12 +2,15 @@
 
 if [ ! -z "${APPNET}" ]; then
     echo "Initial nslookup ${ADMIN_HOST}.${APPNET}"
-    nslookup ${ADMIN_HOST}.${APPNET}
-    while [ $? -ne 0 ]; do
-        echo "Waiting for ${ADMIN_HOST}.${APPNET} to become available"
-        sleep 1
-        nslookup ${ADMIN_HOST}.${APPNET}
+    while [ ! $(dig tasks.${ADMIN_HOST}.${APPNET} +short) ];do \
+        echo "Waiting for ${ADMIN_HOST}.${APPNET} to become available";sleep 1;done
+    for i in $(hostname -i);do
+        if [[ $(echo ${i}|cut -d. -f1-3) == $(dig tasks.${ADMIN_HOST}.${APPNET} +short|cut -d. -f1-3) ]];then
+#            sed -i 's/local.hostname = \${HOSTNAME}.\${APPNET}/local.hostname = ${i}/' /etc/web-registry-portal/application.conf
+            host_ip=${i}
+        fi
     done
+    echo $(dig tasks.${ADMIN_HOST}.${APPNET} +short) > /tmp/admin_ip
 fi
 
 echo "#Dummy" >> /etc/rc.d/init.d/functions
@@ -18,5 +21,5 @@ if [ ! -z "$*" ]
 then
     exec "$@"
 else
-    exec ${WEB_REGISTRY_BIN} ${WEB_REGISTRY_CUSTOM_OPTS} ${WEB_REGISTRY_OPTS}
+    exec TASKS_SERVICE_IP=${host_ip} ${WEB_REGISTRY_BIN} ${WEB_REGISTRY_CUSTOM_OPTS} ${WEB_REGISTRY_OPTS}
 fi

+ 23 - 0
healthcheck.sh

@@ -1,3 +1,26 @@
 #!/bin/bash
 
+curtime=`date +%s`
+
 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=$(dig +short tasks.${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