diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index de46c0fbe7fc..0873deb37c8e 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -2,10 +2,29 @@ start() { # Wait for redis server start before database clean - until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; + until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done + # Wait for configDB initialization + until [[ $(/usr/bin/docker exec database redis-cli -n 4 GET "CONFIG_DB_INITIALIZED") ]]; + do sleep 1; + done + + SYSTEM_WARM_START=`/usr/bin/docker exec database redis-cli -n 4 HGET "WARM_RESTART|system" enable` + SWSS_WARM_START=`/usr/bin/docker exec database redis-cli -n 4 HGET "WARM_RESTART|swss" enable` + # if warm start enabled, just do swss docker start. + # Don't flush DB or try to start other modules. + if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; then + RESTART_COUNT=`redis-cli -n 6 hget "WARM_RESTART_TABLE|orchagent" restart_count` + # We have to make sure db data has not been flushed. + if [[ -n "$RESTART_COUNT" ]]; then + /usr/bin/swss.sh start + /usr/bin/swss.sh attach + return 0 + fi + fi + # Flush DB /usr/bin/docker exec database redis-cli -n 0 FLUSHDB /usr/bin/docker exec database redis-cli -n 1 FLUSHDB @@ -25,14 +44,22 @@ start() { /etc/init.d/xpnet.sh start fi - # start swss and syncd docker - /usr/bin/swss.sh start + # start swss and syncd docker + /usr/bin/swss.sh start /usr/bin/syncd.sh start /usr/bin/swss.sh attach } stop() { /usr/bin/swss.sh stop + + SYSTEM_WARM_START=`redis-cli -n 4 hget "WARM_RESTART|system" enable` + SWSS_WARM_START=`redis-cli -n 4 hget "WARM_RESTART|swss" enable` + # if warm start enabled, just stop swss docker, then return + if [[ "$SYSTEM_WARM_START" == "true" ]] || [[ "$SWSS_WARM_START" == "true" ]]; then + return 0 + fi + /usr/bin/syncd.sh stop # platform specific tasks