diff --git a/dockers/docker-database/Dockerfile.j2 b/dockers/docker-database/Dockerfile.j2 index 8cd18161467..5dc644ae573 100644 --- a/dockers/docker-database/Dockerfile.j2 +++ b/dockers/docker-database/Dockerfile.j2 @@ -34,7 +34,6 @@ RUN apt-get clean -y && \ COPY ["supervisord.conf.j2", "/usr/share/sonic/templates/"] COPY ["docker-database-init.sh", "/usr/local/bin/"] -COPY ["ping_pong_db_insts", "/usr/local/bin/"] COPY ["database_config.json", "/etc/default/sonic-db/"] COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] COPY ["critical_processes", "/etc/supervisor"] diff --git a/dockers/docker-database/ping_pong_db_insts b/dockers/docker-database/ping_pong_db_insts deleted file mode 100755 index 484d4da0cfb..00000000000 --- a/dockers/docker-database/ping_pong_db_insts +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/python -import json -import os -import subprocess -import time -import syslog - -def ping_redis(cmd): - output = '' - while True: - try: - output = subprocess.check_output(cmd, shell=True) - except subprocess.CalledProcessError as e: - syslog.syslog(syslog.LOG_ERR, 'ping redis failed, cmd : {}'.format(cmd)) - - if 'PONG' in output: - break - syslog.syslog(syslog.LOG_ERR, 'ping response : {}'.format(output)) - time.sleep(1) - -database_config_file = "/var/run/redis/sonic-db/database_config.json" - -data = {} -while True: - if os.path.isfile(database_config_file): - with open(database_config_file, "r") as read_file: - data = json.load(read_file) - break - time.sleep(1) - syslog.syslog(syslog.LOG_ERR, 'config file {} does not exist right now'.format(database_config_file)) - -while True: - if 'INSTANCES' in data: - for inst in data["INSTANCES"]: - port = data["INSTANCES"][inst]["port"] - cmd = "redis-cli -p " + str(port) + " ping" - ping_redis(cmd) - break - time.sleep(1) - syslog.syslog(syslog.LOG_ERR, 'config file {} does not have INSTANCES'.format(database_config_file)) diff --git a/dockers/docker-nat/restore_nat_entries.py b/dockers/docker-nat/restore_nat_entries.py index 9fb62e82f57..d07facab290 100755 --- a/dockers/docker-nat/restore_nat_entries.py +++ b/dockers/docker-nat/restore_nat_entries.py @@ -24,7 +24,6 @@ IP_PROTO_TCP = '6' MATCH_CONNTRACK_ENTRY = '^(\w+)\s+(\d+).*src=([\d.]+)\s+dst=([\d.]+)\s+sport=(\d+)\s+dport=(\d+).*src=([\d.]+)\s+dst=([\d.]+)\s+sport=(\d+)\s+dport=(\d+)' -REDIS_SOCK = "/var/run/redis/redis.sock" logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @@ -44,7 +43,7 @@ def add_nat_conntrack_entry_in_kernel(ipproto, srcip, dstip, srcport, dstport, n # Set the statedb "NAT_RESTORE_TABLE|Flags", so natsyncd can start reconciliation def set_statedb_nat_restore_done(): - statedb = swsscommon.DBConnector(swsscommon.STATE_DB, REDIS_SOCK, 0) + statedb = swsscommon.DBConnector("STATE_DB", 0) tbl = swsscommon.Table(statedb, "NAT_RESTORE_TABLE") fvs = swsscommon.FieldValuePairs([("restored", "true")]) tbl.set("Flags", fvs) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index c48d72ea1f4..d071cbe93cb 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -78,7 +78,11 @@ function postStartAction() link_namespace $DEV fi # Wait until redis starts - /usr/bin/docker exec database$DEV ping_pong_db_insts + # TODO: should use $SONIC_DB_CLI if Judy's PR 4477 is in first, otherwise PR 4477 should change this part + until [[ $(/usr/bin/sonic-netns-exec "$NET_NS" sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do + sleep 1; + done + if [[ ("$BOOT_TYPE" == "warm" || "$BOOT_TYPE" == "fastfast") && -f $WARM_DIR/dump.rdb ]]; then rm -f $WARM_DIR/dump.rdb else diff --git a/files/image_config/warmboot-finalizer/finalize-warmboot.sh b/files/image_config/warmboot-finalizer/finalize-warmboot.sh index 0f9e0f7da29..01ad921137b 100755 --- a/files/image_config/warmboot-finalizer/finalize-warmboot.sh +++ b/files/image_config/warmboot-finalizer/finalize-warmboot.sh @@ -29,7 +29,9 @@ function wait_for_database_service() debug "Wait for database to become ready..." # Wait for redis server start before database clean - /usr/bin/docker exec database ping_pong_db_insts + until [[ $(sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do + sleep 1; + done # Wait for configDB initialization until [[ $(sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; diff --git a/files/scripts/configdb-load.sh b/files/scripts/configdb-load.sh index b1bf761371b..fde2de5c6f2 100755 --- a/files/scripts/configdb-load.sh +++ b/files/scripts/configdb-load.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Wait until redis starts -until [[ $(redis-cli ping | grep -c PONG) -gt 0 ]]; do +until [[ $(sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do sleep 1; done diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 360e331f363..df0debf21d9 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -51,7 +51,10 @@ function validate_restore_count() function wait_for_database_service() { # Wait for redis server start before database clean - /usr/bin/docker exec database$DEV ping_pong_db_insts + # TODO: should use $SONIC_DB_CLI if Judy's PR 4477 is in first, otherwise PR 4477 should change this part + until [[ $(/usr/bin/sonic-netns-exec "$NET_NS" sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do + sleep 1; + done # Wait for configDB initialization until [[ $(sonic-netns-exec "$NET_NS" sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]]; diff --git a/files/scripts/syncd.sh b/files/scripts/syncd.sh index 9847cfec940..04a6f5d5282 100755 --- a/files/scripts/syncd.sh +++ b/files/scripts/syncd.sh @@ -39,7 +39,10 @@ function check_warm_boot() function wait_for_database_service() { # Wait for redis server start before database clean - /usr/bin/docker exec database$DEV ping_pong_db_insts + # TODO: should use $SONIC_DB_CLI if Judy's PR 4477 is in first, otherwise PR 4477 should change this part + until [[ $(/usr/bin/sonic-netns-exec "$NET_NS" sonic-db-cli PING | grep -c PONG) -gt 0 ]]; do + sleep 1; + done # Wait for configDB initialization until [[ $(sonic-netns-exec "$NET_NS" sonic-db-cli CONFIG_DB GET "CONFIG_DB_INITIALIZED") ]];