Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGP warm reboot script to service #3992

Merged
merged 18 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
# Copy swss and syncd service script
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

# Copy sonic-netns-exec script
sudo LANG=C cp $SCRIPTS_DIR/sonic-netns-exec $FILESYSTEM_ROOT/usr/bin/sonic-netns-exec
Expand Down
92 changes: 92 additions & 0 deletions files/scripts/bgp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

SERVICE="bgp"
DEBUGLOG="/tmp/bgp_debug.log"

function debug()
{
/usr/bin/logger $1
/bin/echo `date` "- $1" >> ${DEBUGLOG}
}

function check_warm_boot()
{
SYSTEM_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|system" enable`
yxieca marked this conversation as resolved.
Show resolved Hide resolved
SERVICE_WARM_START=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable`
yxieca marked this conversation as resolved.
Show resolved Hide resolved
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=`/usr/bin/redis-cli -n 6 hget "WARM_RESTART_TABLE|bgp" restore_count`
yxieca marked this conversation as resolved.
Show resolved Hide resolved
# 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
}
yxieca marked this conversation as resolved.
Show resolved Hide resolved

start() {
debug "Starting ${SERVICE} service..."

check_warm_boot
validate_restore_count

check_fast_boot

debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}."
debug "Fast boot flag: ${SERVICE} ${Fast_BOOT}."

# start service docker
/usr/bin/${SERVICE}.sh start
debug "Started ${SERVICE} service..."

}

attach() {
/usr/bin/${SERVICE}.sh attach
}

stop() {
debug "Stopping ${SERVICE} service..."

check_warm_boot
check_fast_boot
debug "Warm boot flag: ${SERVICE} ${WARM_BOOT}."
debug "Fast boot flag: ${SERVICE} ${FAST_BOOT}."

# Kill bgpd to start the bgp graceful restart procedure
if [[ x"$WARM_BOOT" == x"true" ]] || [[ x"$FAST_BOOT" == x"true" ]]; then
debug "Kill zebra first"
/usr/bin/docker exec -i bgp pkill -9 zebra
yxieca marked this conversation as resolved.
Show resolved Hide resolved
/usr/bin/docker exec -i bgp pkill -9 bgpd || [ $? == 1 ]
fi

/usr/bin/${SERVICE}.sh stop
debug "Stopped ${SERVICE} service..."

}

case "$1" in
start|attach|stop)
$1
;;
*)
echo "Usage: $0 {start|attach|stop}"
exit 1
;;
esac