From d16d163fc41c34e129cdfa61d3f27ad51984b197 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Wed, 8 Jan 2020 10:14:37 -0800 Subject: [PATCH 01/13] [sonic-buildimage] Move BGP warm reboot scripts into BGP service /usr/local/bin --- files/scripts/bgp.sh | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 files/scripts/bgp.sh diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh new file mode 100644 index 000000000000..253dc347ecbe --- /dev/null +++ b/files/scripts/bgp.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +SERVICE="bgp" +DEBUGLOG="/tmp/bgp_debug.log" +LOCKFILE="/tmp/bgp-lock" + +function debug() +{ + /usr/bin/logger $1 + /bin/echo `date` "- $1" >> ${DEBUGLOG} +} + +function lock_service_state_change() +{ + debug "Locking ${LOCKFILE} from ${SERVICE} service" + + exec {LOCKFD}>${LOCKFILE} + /usr/bin/flock -x ${LOCKFD} + trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15 + + debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" +} + +function unlock_service_state_change() +{ + debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" + /usr/bin/flock -u ${LOCKFD} +} + +function check_warm_boot() +{ + STATE_DBID_PORT=`python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("STATE_DB")'` + SYSTEM_WARM_START=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then + WARM_BOOT="true" + else + WARM_BOOT="false" + fi +} + +function validate_restore_count() +{ + if [[ x"$WARM_BOOT" == x"true" ]]; then + STATE_DBID_PORT=`python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("STATE_DB")'` + RESTORE_COUNT=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_TABLE|orchagent" restore_count` + # We have to make sure db data has not been flushed. + if [[ -z "$RESTORE_COUNT" ]]; then + WARM_BOOT="false" + fi + fi +} + +function wait_for_database_service() +{ + # Wait for redis server start before database clean + ping_pong_db_insts + + # Wait for configDB initialization + until [[ $(/usr/bin/docker exec database redis-cli `python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("CONFIG_DB")'` GET "CONFIG_DB_INITIALIZED") ]]; + do sleep 1; + done +} + +start() { + debug "Starting ${SERVICE} service..." + + lock_service_state_change + + wait_for_database_service + check_warm_boot + validate_restore_count + + debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + + # start service docker + /usr/bin/${SERVICE}.sh start + debug "Started ${SERVICE} service..." + + # Unlock has to happen before reaching out to peer service + unlock_service_state_change +} + +attach() { + startPeerService + /usr/bin/${SERVICE}.sh attach +} + +stop() { + debug "Stopping ${SERVICE} service..." + + [[ -f ${LOCKFILE} ]] || /usr/bin/touch ${LOCKFILE} + + lock_service_state_change + check_warm_boot + debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." + + # Kill bgpd to start the bgp graceful restart procedure, otherwise it sends Notification to peer + debug "Stopping ${SERVICE} service..." + /usr/bin/docker exec -i bgp pkill -9 zebra + /usr/bin/docker exec -i bgp pkill -9 bgpd || [ $? == 1 ] + + /usr/bin/${SERVICE}.sh stop + debug "Stopped ${SERVICE} service..." + + # Unlock has to happen before reaching out to peer service + unlock_service_state_change +} + +case "$1" in + start|attach|stop) + $1 + ;; + *) + echo "Usage: $0 {start|attach|stop}" + exit 1 + ;; +esac From 93add80c37755d1c74a02f4ddf5d7a9c5eed2040 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Wed, 8 Jan 2020 10:19:25 -0800 Subject: [PATCH 02/13] Revert "[sonic-buildimage] Move BGP warm reboot scripts into BGP service /usr/local/bin" This reverts commit d16d163fc41c34e129cdfa61d3f27ad51984b197. --- files/scripts/bgp.sh | 118 ------------------------------------------- 1 file changed, 118 deletions(-) delete mode 100644 files/scripts/bgp.sh diff --git a/files/scripts/bgp.sh b/files/scripts/bgp.sh deleted file mode 100644 index 253dc347ecbe..000000000000 --- a/files/scripts/bgp.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -SERVICE="bgp" -DEBUGLOG="/tmp/bgp_debug.log" -LOCKFILE="/tmp/bgp-lock" - -function debug() -{ - /usr/bin/logger $1 - /bin/echo `date` "- $1" >> ${DEBUGLOG} -} - -function lock_service_state_change() -{ - debug "Locking ${LOCKFILE} from ${SERVICE} service" - - exec {LOCKFD}>${LOCKFILE} - /usr/bin/flock -x ${LOCKFD} - trap "/usr/bin/flock -u ${LOCKFD}" 0 2 3 15 - - debug "Locked ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" -} - -function unlock_service_state_change() -{ - debug "Unlocking ${LOCKFILE} (${LOCKFD}) from ${SERVICE} service" - /usr/bin/flock -u ${LOCKFD} -} - -function check_warm_boot() -{ - STATE_DBID_PORT=`python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("STATE_DB")'` - SYSTEM_WARM_START=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_ENABLE_TABLE|system" enable` - SERVICE_WARM_START=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` - if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then - WARM_BOOT="true" - else - WARM_BOOT="false" - fi -} - -function validate_restore_count() -{ - if [[ x"$WARM_BOOT" == x"true" ]]; then - STATE_DBID_PORT=`python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("STATE_DB")'` - RESTORE_COUNT=`/usr/bin/redis-cli $STATE_DBID_PORT hget "WARM_RESTART_TABLE|orchagent" restore_count` - # We have to make sure db data has not been flushed. - if [[ -z "$RESTORE_COUNT" ]]; then - WARM_BOOT="false" - fi - fi -} - -function wait_for_database_service() -{ - # Wait for redis server start before database clean - ping_pong_db_insts - - # Wait for configDB initialization - until [[ $(/usr/bin/docker exec database redis-cli `python -c 'from swsssdk import _get_redis_dbid_port; print _get_redis_dbid_port("CONFIG_DB")'` GET "CONFIG_DB_INITIALIZED") ]]; - do sleep 1; - done -} - -start() { - debug "Starting ${SERVICE} service..." - - lock_service_state_change - - wait_for_database_service - check_warm_boot - validate_restore_count - - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." - - # start service docker - /usr/bin/${SERVICE}.sh start - debug "Started ${SERVICE} service..." - - # Unlock has to happen before reaching out to peer service - unlock_service_state_change -} - -attach() { - startPeerService - /usr/bin/${SERVICE}.sh attach -} - -stop() { - debug "Stopping ${SERVICE} service..." - - [[ -f ${LOCKFILE} ]] || /usr/bin/touch ${LOCKFILE} - - lock_service_state_change - check_warm_boot - debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}." - - # Kill bgpd to start the bgp graceful restart procedure, otherwise it sends Notification to peer - debug "Stopping ${SERVICE} service..." - /usr/bin/docker exec -i bgp pkill -9 zebra - /usr/bin/docker exec -i bgp pkill -9 bgpd || [ $? == 1 ] - - /usr/bin/${SERVICE}.sh stop - debug "Stopped ${SERVICE} service..." - - # Unlock has to happen before reaching out to peer service - unlock_service_state_change -} - -case "$1" in - start|attach|stop) - $1 - ;; - *) - echo "Usage: $0 {start|attach|stop}" - exit 1 - ;; -esac From 5e4b0250e25739f97dc68cdcbcfd5afbfeb29f50 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Wed, 12 Aug 2020 17:26:31 +0000 Subject: [PATCH 03/13] Move teamd warm reboot functions to service scripts --- .../per_namespace/teamd.service.j2 | 6 +- .../build_templates/sonic_debian_extension.j2 | 1 + files/scripts/teamd.sh | 111 ++++++++++++++++++ 3 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 files/scripts/teamd.sh diff --git a/files/build_templates/per_namespace/teamd.service.j2 b/files/build_templates/per_namespace/teamd.service.j2 index 092f9d2ebde2..322ffdc407ed 100644 --- a/files/build_templates/per_namespace/teamd.service.j2 +++ b/files/build_templates/per_namespace/teamd.service.j2 @@ -9,9 +9,9 @@ StartLimitBurst=3 [Service] User={{ sonicadmin_user }} -ExecStartPre=/usr/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} -ExecStart=/usr/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} -ExecStop=/usr/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} +ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %} +ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %} +ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %} Restart=always RestartSec=30 diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 37b264304fb3..620891038702 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -540,6 +540,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh +sudo LANG=C cp $SCRIPTS_DIR/teamd.sh $FILESYSTEM_ROOT/usr/local/bin/teamd.sh # Copy sonic-netns-exec script sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh new file mode 100644 index 000000000000..873d7ef8704c --- /dev/null +++ b/files/scripts/teamd.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +function debug() +{ + /usr/bin/logger $1 + /bin/echo `date` "- $1" >> ${DEBUGLOG} +} + +function check_warm_boot() +{ + SYSTEM_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` + SERVICE_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` + if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then + WARM_BOOT="true" + else + WARM_BOOT="false" + fi +} + +function validate_restore_count() +{ + if [[ x"$WARM_BOOT" == x"true" ]]; then + RESTORE_COUNT=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_TABLE|teamd" restore_count` + # We have to make sure db data has not been flushed. + if [[ -z "$RESTORE_COUNT" ]]; then + WARM_BOOT="false" + fi + fi +} + +function check_fast_boot () +{ + if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then + FAST_BOOT = "true" + else + FAST_BOOT = "false" + fi +} + +start() { + debug "Starting ${SERVICE}$DEV service..." + + check_warm_boot + validate_restore_count + + check_fast_boot + + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." + debug "Fast boot flag: ${SERVICE}$DEV ${Fast_BOOT}." + + # start service docker + /usr/bin/${SERVICE}.sh start $DEV + debug "Started ${SERVICE}$DEV service..." + +} + +wait() { + /usr/bin/${SERVICE}.sh wait $DEV +} + +stop() { + debug "Stopping ${SERVICE}$DEV service..." + + check_warm_boot + check_fast_boot + debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." + debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}." + + if [[ x"$WARM_BOOT" == x"true" ]] || [[ x"$FAST_BOOT" == x"true" ]]; then + # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames + # We call `docker kill teamd` to ensure the container stops as quickly as possible, + # then immediately call `systemctl stop teamd` to prevent the service from + # restarting the container automatically. + # Note: teamd must be killed before syncd, because it will send the last packet through CPU port + debug "Stopping teamd ..." + docker exec -i teamd pkill -USR2 teamd || [ $? == 1 ] + while docker exec -i teamd pgrep teamd > /dev/null; do + sleep 0.05 + done + docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." + systemctl stop teamd + debug "Stopped teamd ..." + fi + + /usr/bin/${SERVICE}.sh stop $DEV + debug "Stopped ${SERVICE}$DEV service..." + +} + +DEV=$2 + +SERVICE="teamd" +DEBUGLOG="/tmp/teamd-debug$DEV.log" +NAMESPACE_PREFIX="asic" +if [ "$DEV" ]; then + NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace + SONIC_DB_CLI="sonic-db-cli -n $NET_NS" +else + NET_NS="" + SONIC_DB_CLI="sonic-db-cli" +fi + +case "$1" in + start|wait|stop) + $1 + ;; + *) + echo "Usage: $0 {start|wait|stop}" + exit 1 + ;; +esac From 76cb10af52c7648a22cab92811ec570595b9447b Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Wed, 26 Aug 2020 06:49:28 +0000 Subject: [PATCH 04/13] Move teamd warm reboot code to teamd service at /usr/local/bin --- files/scripts/teamd.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 873d7ef8704c..2dcb3994e689 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -80,11 +80,10 @@ stop() { docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." systemctl stop teamd debug "Stopped teamd ..." + else + /usr/bin/${SERVICE}.sh stop $DEV + debug "Stopped ${SERVICE}$DEV service..." fi - - /usr/bin/${SERVICE}.sh stop $DEV - debug "Stopped ${SERVICE}$DEV service..." - } DEV=$2 From 628d41fa10d671abe52ea0409cfa6fb3742242ca Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Wed, 26 Aug 2020 06:52:31 +0000 Subject: [PATCH 05/13] Move teamd warm reboot code to service script --- files/scripts/teamd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 2dcb3994e689..3f8d12b51afe 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -80,7 +80,7 @@ stop() { docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." systemctl stop teamd debug "Stopped teamd ..." - else + else /usr/bin/${SERVICE}.sh stop $DEV debug "Stopped ${SERVICE}$DEV service..." fi From e06df98c84639ced8c5841c298d993613f800d33 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Tue, 20 Oct 2020 10:00:49 -0700 Subject: [PATCH 06/13] Address review comments: pass different sigusr to warm reboot and fast reboot based on latest community code --- files/scripts/teamd.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 3f8d12b51afe..af7ad9c013d1 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -66,7 +66,14 @@ stop() { debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}." - if [[ x"$WARM_BOOT" == x"true" ]] || [[ x"$FAST_BOOT" == x"true" ]]; then + if [[ x"$WARM_BOOT" == x"true" ]]; then + debug "Stopping teamd ..." + # Send USR1 signal to all teamd instances to stop them + # It will prepare teamd for warm-reboot + # Note: We must send USR1 signal before syncd, because it will send the last packet through CPU port + docker exec -i teamd pkill -USR1 teamd > /dev/null || [ $? == 1 ] + debug "Stopped teamd ..." + elif [[ x"$FAST_BOOT" == x"true" ]]; then # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames # We call `docker kill teamd` to ensure the container stops as quickly as possible, # then immediately call `systemctl stop teamd` to prevent the service from From 95ac98f7043a4bbcc398eb2f9e9d047b85650cdd Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Tue, 20 Oct 2020 10:10:58 -0700 Subject: [PATCH 07/13] Address code review comment: pass different sigusr to warm reboot and fast reboot based on latest community code --- files/scripts/teamd.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index af7ad9c013d1..80efe3fd7e65 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -67,29 +67,29 @@ stop() { debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}." if [[ x"$WARM_BOOT" == x"true" ]]; then - debug "Stopping teamd ..." - # Send USR1 signal to all teamd instances to stop them - # It will prepare teamd for warm-reboot - # Note: We must send USR1 signal before syncd, because it will send the last packet through CPU port - docker exec -i teamd pkill -USR1 teamd > /dev/null || [ $? == 1 ] - debug "Stopped teamd ..." + debug "Stopping teamd ..." + # Send USR1 signal to all teamd instances to stop them + # It will prepare teamd for warm-reboot + # Note: We must send USR1 signal before syncd, because it will send the last packet through CPU port + docker exec -i teamd pkill -USR1 teamd > /dev/null || [ $? == 1 ] + debug "Stopped teamd ..." elif [[ x"$FAST_BOOT" == x"true" ]]; then - # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames - # We call `docker kill teamd` to ensure the container stops as quickly as possible, - # then immediately call `systemctl stop teamd` to prevent the service from - # restarting the container automatically. - # Note: teamd must be killed before syncd, because it will send the last packet through CPU port - debug "Stopping teamd ..." - docker exec -i teamd pkill -USR2 teamd || [ $? == 1 ] - while docker exec -i teamd pgrep teamd > /dev/null; do - sleep 0.05 - done - docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." - systemctl stop teamd - debug "Stopped teamd ..." + # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames + # We call `docker kill teamd` to ensure the container stops as quickly as possible, + # then immediately call `systemctl stop teamd` to prevent the service from + # restarting the container automatically. + # Note: teamd must be killed before syncd, because it will send the last packet through CPU port + debug "Stopping teamd ..." + docker exec -i teamd pkill -USR2 teamd || [ $? == 1 ] + while docker exec -i teamd pgrep teamd > /dev/null; do + sleep 0.05 + done + docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." + systemctl stop teamd + debug "Stopped teamd ..." else - /usr/bin/${SERVICE}.sh stop $DEV - debug "Stopped ${SERVICE}$DEV service..." + /usr/bin/${SERVICE}.sh stop $DEV + debug "Stopped ${SERVICE}$DEV service..." fi } From 02f3abfb35a34241e1aa3d2b69bbaf66a2dcc8d2 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Mon, 26 Oct 2020 17:13:18 -0700 Subject: [PATCH 08/13] Address code review comments: 1) remove space in variable assignement 2) apply multi-asic support to script --- files/scripts/teamd.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 80efe3fd7e65..c43f49fedbf9 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -31,9 +31,9 @@ function validate_restore_count() function check_fast_boot () { if [[ $($SONIC_DB_CLI STATE_DB GET "FAST_REBOOT|system") == "1" ]]; then - FAST_BOOT = "true" + FAST_BOOT="true" else - FAST_BOOT = "false" + FAST_BOOT="false" fi } @@ -67,30 +67,28 @@ stop() { debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}." if [[ x"$WARM_BOOT" == x"true" ]]; then - debug "Stopping teamd ..." # Send USR1 signal to all teamd instances to stop them # It will prepare teamd for warm-reboot # Note: We must send USR1 signal before syncd, because it will send the last packet through CPU port - docker exec -i teamd pkill -USR1 teamd > /dev/null || [ $? == 1 ] - debug "Stopped teamd ..." + docker exec -i ${SERVICE}$DEV pkill -USR1 ${SERVICE} > /dev/null || [ $? == 1 ] + elif [[ x"$FAST_BOOT" == x"true" ]]; then # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames # We call `docker kill teamd` to ensure the container stops as quickly as possible, # then immediately call `systemctl stop teamd` to prevent the service from # restarting the container automatically. # Note: teamd must be killed before syncd, because it will send the last packet through CPU port - debug "Stopping teamd ..." - docker exec -i teamd pkill -USR2 teamd || [ $? == 1 ] - while docker exec -i teamd pgrep teamd > /dev/null; do + docker exec -i ${SERVICE}$DEV pkill -USR2 ${SERVICE} || [ $? == 1 ] + while docker exec -i ${SERVICE}$DEV pgrep ${SERVICE} > /dev/null; do sleep 0.05 done - docker kill teamd &> /dev/null || debug "Docker teamd is not running ($?) ..." - systemctl stop teamd - debug "Stopped teamd ..." + docker kill ${SERVICE}$DEV &> /dev/null || debug "Docker ${SERVICE}$DEV is not running ($?) ..." + systemctl stop ${SERVICE}$DEV else /usr/bin/${SERVICE}.sh stop $DEV - debug "Stopped ${SERVICE}$DEV service..." fi + + debug "Stopped ${SERVICE}$DEV service..." } DEV=$2 From c92751916cb6dd25a309ed8d34fb19b6ea809a10 Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Mon, 26 Oct 2020 17:19:57 -0700 Subject: [PATCH 09/13] Address code review comments: 1) Remove space in variable assignement 2) Apply multi-asic support --- files/scripts/teamd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index c43f49fedbf9..95d28e350e47 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -88,7 +88,7 @@ stop() { /usr/bin/${SERVICE}.sh stop $DEV fi - debug "Stopped ${SERVICE}$DEV service..." + debug "Stopped ${SERVICE}$DEV service..." } DEV=$2 From c7e32db9021acec4e2ecc359da220988fd75d3ea Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Mon, 26 Oct 2020 21:15:13 -0700 Subject: [PATCH 10/13] Address code review comment: 1) Remove "systemctl stop ${SERVICE}$DEV" for fast-reboot 2) Call /user/bin/teamd.sh to stop teamd for all cases --- files/scripts/teamd.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 95d28e350e47..2e19c41702a3 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -71,7 +71,6 @@ stop() { # It will prepare teamd for warm-reboot # Note: We must send USR1 signal before syncd, because it will send the last packet through CPU port docker exec -i ${SERVICE}$DEV pkill -USR1 ${SERVICE} > /dev/null || [ $? == 1 ] - elif [[ x"$FAST_BOOT" == x"true" ]]; then # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames # We call `docker kill teamd` to ensure the container stops as quickly as possible, @@ -83,11 +82,9 @@ stop() { sleep 0.05 done docker kill ${SERVICE}$DEV &> /dev/null || debug "Docker ${SERVICE}$DEV is not running ($?) ..." - systemctl stop ${SERVICE}$DEV - else - /usr/bin/${SERVICE}.sh stop $DEV fi + /usr/bin/${SERVICE}.sh stop $DEV debug "Stopped ${SERVICE}$DEV service..." } From 0570547361e0b22351c6a0e6c98150a158bd199c Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Mon, 26 Oct 2020 22:48:39 -0700 Subject: [PATCH 11/13] Update comment context to reflect current code --- files/scripts/teamd.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index 2e19c41702a3..d87347628a28 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -74,8 +74,6 @@ stop() { elif [[ x"$FAST_BOOT" == x"true" ]]; then # Kill teamd processes inside of teamd container with SIGUSR2 to allow them to send last LACP frames # We call `docker kill teamd` to ensure the container stops as quickly as possible, - # then immediately call `systemctl stop teamd` to prevent the service from - # restarting the container automatically. # Note: teamd must be killed before syncd, because it will send the last packet through CPU port docker exec -i ${SERVICE}$DEV pkill -USR2 ${SERVICE} || [ $? == 1 ] while docker exec -i ${SERVICE}$DEV pgrep ${SERVICE} > /dev/null; do From e1538e9cc7baf5c3e80c64b9d36631406ee6932b Mon Sep 17 00:00:00 2001 From: "heidi.ou@alibaba-inc.com" Date: Fri, 30 Oct 2020 20:16:04 -0700 Subject: [PATCH 12/13] Address code revew comments: update comments and remove unused variables and unnecessary space --- files/build_templates/sonic_debian_extension.j2 | 2 +- files/scripts/teamd.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 4c0f2a42e100..66f6b8b4e3af 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -529,7 +529,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys {% endif %} -# Copy service scripts (swss, syncd, bgp, radv) +# Copy service scripts (swss, syncd, bgp, teamd, radv) sudo LANG=C cp $SCRIPTS_DIR/swss.sh $FILESYSTEM_ROOT/usr/local/bin/swss.sh sudo LANG=C cp $SCRIPTS_DIR/syncd.sh $FILESYSTEM_ROOT/usr/local/bin/syncd.sh sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh index d87347628a28..626bb5186ca0 100644 --- a/files/scripts/teamd.sh +++ b/files/scripts/teamd.sh @@ -20,7 +20,7 @@ function check_warm_boot() function validate_restore_count() { if [[ x"$WARM_BOOT" == x"true" ]]; then - RESTORE_COUNT=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_TABLE|teamd" restore_count` + RESTORE_COUNT=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_TABLE|${SERVICE}" restore_count` # We have to make sure db data has not been flushed. if [[ -z "$RESTORE_COUNT" ]]; then WARM_BOOT="false" @@ -51,7 +51,6 @@ start() { # start service docker /usr/bin/${SERVICE}.sh start $DEV debug "Started ${SERVICE}$DEV service..." - } wait() { @@ -95,7 +94,6 @@ if [ "$DEV" ]; then NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace SONIC_DB_CLI="sonic-db-cli -n $NET_NS" else - NET_NS="" SONIC_DB_CLI="sonic-db-cli" fi From 8a4e6340b709c4a61f192bc03dea1aadfc99b69f Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Fri, 13 Nov 2020 01:54:32 +0000 Subject: [PATCH 13/13] chmod +x teamd.sh Signed-off-by: Ying Xie --- files/scripts/teamd.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 files/scripts/teamd.sh diff --git a/files/scripts/teamd.sh b/files/scripts/teamd.sh old mode 100644 new mode 100755