From 8c7993e9c006a40cb57cd91bb66178951e53b1f2 Mon Sep 17 00:00:00 2001 From: Shu0T1an ChenG Date: Mon, 12 Nov 2018 17:23:50 -0800 Subject: [PATCH] [teamd]: Add teamd.sh start script to clean up STATE database To align the startup approach same with syncd and swss docker. Clean up the state databsae for LAGs when starting the docker. Remove all obsolete netdevs before creating new ones. Signed-off-by: Shu0T1an ChenG --- dockers/docker-teamd/start.sh | 6 +++ files/build_templates/teamd.service.j2 | 5 +-- files/scripts/teamd.sh | 61 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100755 files/scripts/teamd.sh diff --git a/dockers/docker-teamd/start.sh b/dockers/docker-teamd/start.sh index 4cbc65ab0cc3..3bf11c684436 100755 --- a/dockers/docker-teamd/start.sh +++ b/dockers/docker-teamd/start.sh @@ -3,6 +3,12 @@ rm -f /var/run/rsyslogd.pid rm -f /var/run/teamd/* +if [[ x"$WARM_BOOT" != x"true" ]]; then + for pc in `ip link show | grep PortChannel | awk -F "[ :]" '{print $3}'`; + do ip link delete dev $pc + done +fi + mkdir -p /var/warmboot/teamd supervisorctl start rsyslogd diff --git a/files/build_templates/teamd.service.j2 b/files/build_templates/teamd.service.j2 index bbd04a81b05b..3150a5d269f3 100644 --- a/files/build_templates/teamd.service.j2 +++ b/files/build_templates/teamd.service.j2 @@ -5,9 +5,8 @@ After=updategraph.service [Service] User={{ sonicadmin_user }} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start -ExecStart=/usr/bin/{{docker_container_name}}.sh attach -ExecStop=/usr/bin/{{docker_container_name}}.sh stop +ExecStart=/usr/local/bin/{{docker_container_name}}.sh attach +ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop [Install] WantedBy=multi-user.target diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh new file mode 100755 index 000000000000..5317df76f8cb --- /dev/null +++ b/files/scripts/teamd.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +SERVICE="teamd" +DEBUGLOG="/tmp/teamd-debug.log" + +function debug() +{ + /bin/echo `date` "- $1" >> ${DEBUGLOG} +} + +function wait_for_database_service() +{ + # Wait for redis server start before database clean + 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 +} + +function clean_up_tables() +{ + redis-cli -n $1 EVAL " + local tables = {$2} + for i = 1, table.getn(tables) do + local matches = redis.call('KEYS', tables[i]) + for j,name in ipairs(matches) do + redis.call('DEL', name) + end + end" 0 +} + +start() { + debug "Starting ${SERVICE} service..." + + wait_for_database_service + + clean_up_tables 6 "LAG_TABLE*" + + /usr/bin/${SERVICE}.sh start + /usr/bin/${SERVICE}.sh attach +} + + +stop() { + debug "Stopping ${SERVICE} service..." + /usr/bin/${SERVICE}.sh stop +} + +case "$1" in + start|stop) + $1 + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac