Skip to content

Commit 45d85c9

Browse files
yxiecalguohan
authored andcommitted
[warm boot] move warm reboot/fast reboot knowledge to syncd service script (#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]>
1 parent ac67208 commit 45d85c9

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

scripts/fast-reboot

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
#!/bin/bash
1+
#!/bin/bash -e
22

33
REBOOT_USER=$(logname)
44
REBOOT_TIME=$(date)
55
REBOOT_CAUSE_FILE="/var/cache/sonic/reboot-cause.txt"
66
REBOOT_TYPE=$(basename $0)
7+
WARM_DIR=/host/warmboot
8+
9+
function clear_warm_boot()
10+
{
11+
config warm_restart disable || /bin/true
12+
13+
TIMESTAMP=`date +%Y%m%d-%H%M%S`
14+
if [[ -f ${WARM_DIR}/config_db.json ]]; then
15+
mv -f ${WARM_DIR}/config_db.json ${WARM_DIR}/config_db-${TIMESTAMP}.json || /bin/true
16+
fi
17+
}
718

819
# Check reboot type supported
920
BOOT_TYPE_ARG="cold"
@@ -13,6 +24,8 @@ case "$REBOOT_TYPE" in
1324
;;
1425
"warm-reboot")
1526
BOOT_TYPE_ARG="warm"
27+
trap clear_warm_boot EXIT HUP INT QUIT TERM KILL ABRT ALRM
28+
config warm_restart enable system
1629
;;
1730
*)
1831
echo "Not supported reboot type: $REBOOT_TYPE" >&2
@@ -119,15 +132,15 @@ fi
119132
# Kill swss dockers
120133
docker kill swss
121134

135+
# syncd service stop is capable of handling both warm/fast/cold shutdown
136+
systemctl stop syncd
137+
122138
# Warm reboot: dump state to host disk
123139
# Note: even if syncd changed ASIC_DB before killed, we don't care
124140
if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
125-
# Set whole system warm reboot flag
126-
config warm_restart enable system
127141
# Dump redis content to directory
128142
# Note: don't use pretty mode redis-dump (1.1) since there is a known bug with key pattern
129143
DUMP_CMD="redis-dump -s /var/run/redis/redis.sock"
130-
WARM_DIR=/host/warmboot
131144
mkdir -p $WARM_DIR
132145
# Note: requiring redis-dump-load
133146
# Save applDB in /host/warm-reboot/appl_db.json
@@ -144,23 +157,6 @@ if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
144157
$DUMP_CMD -d 3 -o $WARM_DIR/loglevel_db.json
145158
fi
146159

147-
if [[ "$REBOOT_TYPE" = "warm-reboot" ]]; then
148-
# Gracefully stop syncd for warm-reboot
149-
systemctl stop syncd
150-
elif [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then
151-
# syncd graceful stop for fast-reboot is supported only for Broadcom platforms only for now
152-
if [[ "$sonic_asic_type" = 'broadcom' ]]; then
153-
# Gracefully stop syncd
154-
docker exec -i syncd /usr/bin/syncd_request_shutdown --cold > /dev/null
155-
156-
# Check that syncd was stopped
157-
while docker top syncd | grep -q /usr/bin/syncd
158-
do
159-
sleep 0.1
160-
done
161-
fi
162-
fi
163-
164160
# Kill other containers to make the reboot faster
165161
docker ps -q | xargs docker kill > /dev/null
166162

0 commit comments

Comments
 (0)