From 1d4c2c74b7a50ddf58ab02674e06e9648ac3677b Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Thu, 28 Feb 2019 23:06:25 -0800 Subject: [PATCH 1/2] [teamd]: wait for swss db flush done before starting teamd container Signed-off-by: Jipan Yang --- files/build_templates/docker_image_ctl.j2 | 20 ++++++++++++++++++++ files/scripts/swss.sh | 1 + 2 files changed, 21 insertions(+) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index a3cbf5adbae7..6fc57fa9c6a5 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -1,5 +1,23 @@ #!/bin/bash +DEBUGLOG="/tmp/{{ docker_container_name }}_debug.log" + +function debug() +{ + /usr/bin/logger $1 + /bin/echo `date` "- $1" >> ${DEBUGLOG} +} + +function wait_for_swss_db_flush_done() +{ + debug "Start waiting for swss" + until [[ $(redis-cli -n 0 GET "SWSS_DB_FLUSH_DONE") ]]; do + debug "Wait 1 second for SWSS_DB_FLUSH_DONE" + sleep 1 + done + debug "Swss db flush done" +} + function getMountPoint() { echo $1 | python -c "import sys, json, os; mnts = [x for x in json.load(sys.stdin)[0]['Mounts'] if x['Destination'] == '/usr/share/sonic/hwsku']; print '' if len(mnts) == 0 else os.path.basename(mnts[0]['Source'])" 2>/dev/null @@ -36,6 +54,8 @@ function preStartAction() echo -n > /tmp/dump.rdb docker cp /tmp/dump.rdb database:/var/lib/redis/ fi +{%- elif docker_container_name == "teamd" %} + wait_for_swss_db_flush_done {%- else %} : # nothing {%- endif %} diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index f7f2e53608f4..de88949f2450 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -97,6 +97,7 @@ start() { /usr/bin/docker exec database redis-cli -n 2 FLUSHDB /usr/bin/docker exec database redis-cli -n 5 FLUSHDB clean_up_tables 6 "'PORT_TABLE*', 'MGMT_PORT_TABLE*', 'VLAN_TABLE*', 'VLAN_MEMBER_TABLE*', 'INTERFACE_TABLE*', 'MIRROR_SESSION*', 'VRF_TABLE*'" + /usr/bin/docker exec database redis-cli -n 0 SET "SWSS_DB_FLUSH_DONE" "1" fi # start service docker From af6fac83c63728896deda817e433a3148b5e332a Mon Sep 17 00:00:00 2001 From: Jipan Yang Date: Fri, 1 Mar 2019 00:26:15 -0800 Subject: [PATCH 2/2] SET "SWSS_DB_FLUSH_DONE" to 0 upon swss service stop Signed-off-by: Jipan Yang --- files/scripts/swss.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index de88949f2450..9eb5ec2435fb 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -130,6 +130,7 @@ stop() { # if warm start enabled or peer lock exists, don't stop peer service docker if [[ x"$WARM_BOOT" != x"true" ]]; then + /usr/bin/docker exec database redis-cli -n 0 SET "SWSS_DB_FLUSH_DONE" "0" /bin/systemctl stop ${PEER} fi }