docker-compose 微服務啓動順序腳本監聽 dubbo

原理說明: command 裏面的find.sh 監聽微服務啓動的log,若是log字段包含多出來的成功字符串 JVM running for 說明已經啓動成功,能夠繼續啓動依賴的服務,保證啓動不報錯,TODO的地方是 超時應發郵件提醒 1.yml文件 xxx-service:java

image: java

    container_name: xxx-service

    restart: always

    volumes:

        - /etc/timezone:/etc/timezone

        - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime

    command: ["/usr/src/wait.sh", "18","nohup java -jar -Xms128m -Xmx256m -XX:PermSize=64M -XX:MaxPermSize=128M /usr/src/myapp/xxx-service.jar > /usr/src/myapp/xxx-service.log &"]

    links:

        - zzz-service



yyy-service:

    image: java

    container_name: yyy-service

    restart: always

    volumes:

        - /etc/timezone:/etc/timezone

        - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime

    command: ["/usr/src/find.sh", "5,hhh-service,www-service","nohup java -jar -Xms128m -Xmx256m -XX:PermSize=64M -XX:MaxPermSize=128M /usr/src/myapp/yyy-service.jar > /usr/src/myapp/yyy-service.log &"]

    links:

        - zzz-service

2.腳本 find.sh #!/bin/bashdocker

source /usr/src/find-set.shbash

set -eapp

time="$1"微服務

echo "***************************************** params $time ****************************************************"rest

shiftcode

x=$time字符串

cmd="$@"cmd

echo "x $x"it

echo "cmd $cmd"

echo "$cmd" >> /usr/src/test.txt

OLD_IFS="$IFS"

IFS=","

array=($x)

IFS="$OLD_IFS"

time=${array[0]}

echo "time $time"

for((i=1;i<${#array[@]};i++));

do 

  elem=${array[$i]}

  echo "$i : $elem"   

  echo $elem

  project=$elem

  findNum=${project//-/_}     

  echo "findNum: $findNum"     

  eval findForNum=\$$findNum

  echo "findForNum: $findForNum"

while(($findForNum == grep -c "$successStr" /xxx/$project/logs/$project.log))

do

echo "waiting ... $findNum"

sleep 5

done

done;

echo "started"

sleep $time

exec $cmd

find-set.sh #!/bin/bash

export successStr='JVM running for'

export basedata_service=grep -c "$successStr" /xxx-service/logs/xxx-service.log

wait.sh #!/bin/bash

wait.sh

set -e

time="$1"

shift

cmd="$@"

sleep $time

exec $cmd

重啓的腳本

#!/bin/bash

restart.sh

cd /home/xxx/compose

docker-compose down

sleep 3

sh /home/xxx//cpjar.sh

sync

echo 3 > /proc/sys/vm/drop_caches

docker-compose up -d

相關文章
相關標籤/搜索