From 582f11f6dc7b7237f18798ee646d762b29eb0f35 Mon Sep 17 00:00:00 2001 From: jh7358 Date: Wed, 12 Dec 2018 17:10:03 -0500 Subject: Restart docker if mariadb fails to start Also modified script to use a different mechanism to get the host IP (copied from CSIT setup.sh), one that should work in developer VMs as well as in the Jenkins environment. Change-Id: Ide454ff827ebd90f55b699f16e5f7f6eb40bd1d1 Issue-ID: POLICY-885 Signed-off-by: Jim Hahn --- scripts/policy/script1.sh | 64 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/scripts/policy/script1.sh b/scripts/policy/script1.sh index 70706921..c47c4bf8 100755 --- a/scripts/policy/script1.sh +++ b/scripts/policy/script1.sh @@ -46,23 +46,15 @@ cd .. ifconfig -if ! ifconfig eth0; then - if ! ifconfig ens3; then - echo "Could not determine IP address" - exit 1 - fi - export IP=`ifconfig ens3 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` -else - export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` +export IP=`ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $NF}'` +if [ -z "$IP" ]; then + echo "Could not determine IP address" + exit 1 fi echo $IP if ! ifconfig docker0; then - if ! ifconfig ens3; then - echo "Could not determine IP address" - exit 1 - fi - export DOCKER_IP_IP=`ifconfig ens3 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` + export DOCKER_IP="$IP" else export DOCKER_IP=`ifconfig docker0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` fi @@ -121,7 +113,49 @@ echo ${NEXUS_IP} MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` echo ${MARIADB_IP} -sleep 5m +sleep 3m + +docker logs mariadb 2>&1 | grep -q "mysqld: ready for connections" +if [ $? -eq 0 ]; then + # mariadb is ok - sleep a little longer for others + sleep 2m + +else + echo mariadb is not ready + echo Restarting... + + docker kill drools pdp pap brmsgw nexus mariadb + docker rm -f drools pdp pap brmsgw nexus mariadb + + docker-compose -f docker-compose-integration.yml up -d + + if [ ! $? -eq 0 ]; then + echo "Docker compose failed" + exit 1 + fi + + docker ps + + POLICY_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' drools` + echo ${POLICY_IP} + + PDP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pdp` + echo ${PDP_IP} + + PAP_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' pap` + echo ${PAP_IP} + + BRMS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' brmsgw` + echo ${BRMS_IP} + + NEXUS_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' nexus` + echo ${NEXUS_IP} + + MARIADB_IP=`docker inspect --format '{{ .NetworkSettings.Networks.docker_default.IPAddress}}' mariadb` + echo ${MARIADB_IP} + + sleep 5m +fi netstat -tnl @@ -160,7 +194,7 @@ INTERVAL=20 TIME=0 while [ "$TIME" -lt "$TIME_OUT" ]; do - curl -k -i -v -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -X POST -d '{"policyName": ".*"}' https://${PDP_IP}:8081/pdp/api/getConfig && break + curl -k -i -v -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'ClientAuth: cHl0aG9uOnRlc3Q=' -H 'Authorization: Basic dGVzdHBkcDphbHBoYTEyMw==' -H 'Environment: TEST' -d '{"policyName": ".*"}' https://${PDP_IP}:8081/pdp/api/getConfig && break echo Sleep: $INTERVAL seconds before testing if Policy is up. Total wait time up now is: $TIME seconds. Timeout is: $TIME_OUT seconds sleep $INTERVAL -- cgit 1.2.3-korg