Skip to content

Commit

Permalink
[warm boot] move warm reboot/fast reboot knowledge to syncd service s…
Browse files Browse the repository at this point in the history
…cript (sonic-net#372)

* [warm boot] set warm boot flag before killing swss docker

Kill swss docker will cause service swss to fail, systemctrl will then
stop swss as result. If the flag is not set, swss will also stop syncd
without letting syncd to warm shutdown.

Signed-off-by: Ying Xie <[email protected]>

* [fast/warm reboot] let syncd service handle different types of shutdowns

Signed-off-by: Ying Xie <[email protected]>

* [warm/fast reboot] stop execution after error

Signed-off-by: Ying Xie <[email protected]>

* [warm boot] set warm boot flag earlier and clear it on error

Signed-off-by: Ying Xie <[email protected]>

* [warm boot] stop syncd before backing up database

Signed-off-by: Ying Xie <[email protected]>
  • Loading branch information
yxieca authored and lguohan committed Nov 15, 2018
1 parent ac67208 commit 45d85c9
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions scripts/fast-reboot
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/bash
#!/bin/bash -e

REBOOT_USER=$(logname)
REBOOT_TIME=$(date)
REBOOT_CAUSE_FILE="/var/cache/sonic/reboot-cause.txt"
REBOOT_TYPE=$(basename $0)
WARM_DIR=/host/warmboot

function clear_warm_boot()
{
config warm_restart disable || /bin/true

TIMESTAMP=`date +%Y%m%d-%H%M%S`
if [[ -f ${WARM_DIR}/config_db.json ]]; then
mv -f ${WARM_DIR}/config_db.json ${WARM_DIR}/config_db-${TIMESTAMP}.json || /bin/true
fi
}

# Check reboot type supported
BOOT_TYPE_ARG="cold"
Expand All @@ -13,6 +24,8 @@ case "$REBOOT_TYPE" in
;;
"warm-reboot")
BOOT_TYPE_ARG="warm"
trap clear_warm_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
config warm_restart enable system
;;
*)
echo "Not supported reboot type: $REBOOT_TYPE" >&2
Expand Down Expand Up @@ -119,15 +132,15 @@ fi
# Kill swss dockers
docker kill swss

# syncd service stop is capable of handling both warm/fast/cold shutdown
systemctl stop syncd

# Warm reboot: dump state to host disk
# Note: even if syncd changed ASIC_DB before killed, we don't care
if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
# Set whole system warm reboot flag
config warm_restart enable system
# Dump redis content to directory
# Note: don't use pretty mode redis-dump (1.1) since there is a known bug with key pattern
DUMP_CMD="redis-dump -s /var/run/redis/redis.sock"
WARM_DIR=/host/warmboot
mkdir -p $WARM_DIR
# Note: requiring redis-dump-load
# Save applDB in /host/warm-reboot/appl_db.json
Expand All @@ -144,23 +157,6 @@ if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
$DUMP_CMD -d 3 -o $WARM_DIR/loglevel_db.json
fi

if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
# Gracefully stop syncd for warm-reboot
systemctl stop syncd
elif [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
# syncd graceful stop for fast-reboot is supported only for Broadcom platforms only for now
if [[ "$sonic_asic_type" = 'broadcom' ]]; then
# Gracefully stop syncd
docker exec -i syncd /usr/bin/syncd_request_shutdown --cold > /dev/null

# Check that syncd was stopped
while docker top syncd | grep -q /usr/bin/syncd
do
sleep 0.1
done
fi
fi

# Kill other containers to make the reboot faster
docker ps -q | xargs docker kill > /dev/null

Expand Down

0 comments on commit 45d85c9

Please sign in to comment.