Move teamd warm reboot code to service script (#5163)
Summary: Move teamd functions to a new service script Motivation: To segregate teamd functions in one common place. fast-reboot script calls teamd functions that should ideally be replaced by a simple call to a service script. Changes: New teamd service script and path modification from /usr/bin/teamd.sh to /usr/local/bin/teamd.sh fast-reboot script (in sonic-utilities) modification (to use new teamd.sh to stop teamd) should follow soon after this change. Verification: VS image tests. Signed-off-by: Vaibhav Hemant Dixit <vaibhav.dixit@microsoft.com> Co-authored-by: heidi.ou@alibaba-inc.com <heidi.ou@alibaba-inc.com> Co-authored-by: Ying Xie <ying.xie@microsoft.com>
This commit is contained in:
parent
56fa3cf494
commit
7c17c58b83
@ -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
|
||||
|
||||
|
@ -565,12 +565,13 @@ 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/syncd_common.sh $FILESYSTEM_ROOT/usr/local/bin/syncd_common.sh
|
||||
sudo LANG=C cp $SCRIPTS_DIR/gbsyncd.sh $FILESYSTEM_ROOT/usr/local/bin/gbsyncd.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
|
||||
sudo LANG=C cp $SCRIPTS_DIR/radv.sh $FILESYSTEM_ROOT/usr/local/bin/radv.sh
|
||||
|
||||
# Copy sonic-netns-exec script
|
||||
|
108
files/scripts/teamd.sh
Executable file
108
files/scripts/teamd.sh
Executable file
@ -0,0 +1,108 @@
|
||||
#!/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|${SERVICE}" 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" ]]; then
|
||||
# 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 ${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,
|
||||
# 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
|
||||
sleep 0.05
|
||||
done
|
||||
docker kill ${SERVICE}$DEV &> /dev/null || debug "Docker ${SERVICE}$DEV is not running ($?) ..."
|
||||
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
|
||||
SONIC_DB_CLI="sonic-db-cli"
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
start|wait|stop)
|
||||
$1
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|wait|stop}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue
Block a user