diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index a2bfb7d125..240a7514d6 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -10,11 +10,8 @@ function postStartAction() {%- if docker_container_name != "database" %} : {%- else %} - while true; do - if [[ "$(docker exec -i database redis-cli ping)" =~ PONG.* ]]; then - break - fi - sleep 1 + until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do + sleep 1; done {%- endif %} {%- if docker_container_name == "snmp" %} diff --git a/files/build_templates/swss.service.j2 b/files/build_templates/swss.service.j2 index b18321676b..ebfb5027b2 100644 --- a/files/build_templates/swss.service.j2 +++ b/files/build_templates/swss.service.j2 @@ -17,7 +17,7 @@ After=nps-modules-3.16.0-4-amd64.service [Service] User=root # Wait for redis server start before database clean -ExecStartPre=/bin/bash -c "while true; do if [ \"$(/usr/bin/docker exec database redis-cli ping)\" == \"PONG\" ]; then break; fi; sleep 1; done" +ExecStartPre=/bin/bash -c 'until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done' ExecStartPre=/usr/bin/docker exec database redis-cli -n 0 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 1 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 2 FLUSHDB diff --git a/files/scripts/configdb-load.sh b/files/scripts/configdb-load.sh index 2175e37d5a..42bb9959bc 100755 --- a/files/scripts/configdb-load.sh +++ b/files/scripts/configdb-load.sh @@ -1,11 +1,8 @@ #!/usr/bin/env bash # Wait until redis starts -while true; do - if [ `redis-cli ping` == "PONG" ]; then - break - fi - sleep 1 +until [[ $(redis-cli ping | grep -c PONG) -gt 0 ]]; do + sleep 1; done # If there is a config db dump file, load it