瀏覽代碼

Add Dockerfile and scripts

Admin User 6 年之前
父節點
當前提交
b640640268
共有 3 個文件被更改,包括 49 次插入0 次删除
  1. 5 0
      Dockerfile
  2. 27 0
      check_ip.sh
  3. 17 0
      docker-entrypoint.sh

+ 5 - 0
Dockerfile

@@ -0,0 +1,5 @@
+FROM alpine:3.8
+ENTRYPOINT ["/tmp/docker-entrypoint.sh"]
+COPY docker-entrypoint.sh \
+     check_ip.sh \
+     /tmp/

+ 27 - 0
check_ip.sh

@@ -0,0 +1,27 @@
+#!/bin/sh
+#service=iru-swarm.infoclinica.ru
+#floating_ip=swarm.sdsys.ru
+
+check_service() {
+  curl -f ${service}
+  if [ $? == 0 ]; then echo "${service} is up and running!!!"; return 0; else echo "${service} is down!!!"; return 1; fi
+}
+
+check_ip() {
+  curl -f ${floating_ip}
+  if [ $? == 0 ]; then echo "${floating_ip} is exist!!!"; return 0; else echo "The ${floating_ip} doesn't exist!"; return 1; fi
+}
+
+check=0
+
+while [ ${check} -eq 0 ]
+do 
+check_service
+if [ $? != 0 ]
+then
+  sleep 10
+else
+  check_ip
+  if [ $? != 0 ]; then check=1; else sleep 10; fi
+fi
+done

+ 17 - 0
docker-entrypoint.sh

@@ -0,0 +1,17 @@
+#!/bin/sh
+#set -e
+
+if [ -z ${service} ]; then echo "The service isn't defined!!!"; exit 1; fi
+if [ -z ${floating_ip} ]; then echo "IP isn't defined!!!"; exit 1; fi
+if [ -z ${floating_mask} ]; then echo "NetMASK isn't defined!!!"; exit 1; fi
+if [ -z ${floating_if} ]; then echo "IF isn't defined!!!"; exit 1; fi
+
+trap cleanup SIGTERM EXIT
+  cleanup()
+    {
+      ip addr del ${floating_ip}/${floating_mask} dev ${floating_if}:floating
+    }
+    ip addr add ${floating_ip}/${floating_mask} brd + dev ${floating_if} label ${floating}:floating
+exec "/tmp/check_ip.sh" "$@" &
+wait
+