Skip to content

Commit 5ab8006

Browse files
authored
[warm reboot] timeout waiting for database operation and add -x option (sonic-net#419)
* [warm reboot] add option -x to execute script in -x mode This option is useful when debugging the warm/fast reboot scripts. Signed-off-by: Ying Xie <[email protected]> * [warm reboot] timeout on database related commands Signed-off-by: Ying Xie <[email protected]> * [warm reboot] retry after tiemout Signed-off-by: Ying Xie <[email protected]> * [warm reboot] retry timeout up to 3 times Signed-off-by: Ying Xie <[email protected]> * Print cancel warm-reboot result after error happened
1 parent 6ab3b9f commit 5ab8006

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

scripts/fast-reboot

+25-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ function showHelpAndExit()
3434
echo " -f : force execution"
3535
echo " -r : reboot with /sbin/reboot [default]"
3636
echo " -k : reboot with /sbin/kexec -e"
37+
echo " -x : execute script with -x flag"
3738

3839
exit 0
3940
}
4041

4142
function parseOptions()
4243
{
43-
while getopts "vfh?rk" opt; do
44+
while getopts "vfh?rkx" opt; do
4445
case ${opt} in
4546
h )
4647
showHelpAndExit
@@ -60,6 +61,9 @@ function parseOptions()
6061
k )
6162
REBOOT_METHOD="/sbin/kexec -e"
6263
;;
64+
x )
65+
set -x
66+
;;
6367
esac
6468
done
6569
}
@@ -69,7 +73,8 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
6973
function clear_warm_boot()
7074
{
7175
debug "Failure ($?) cleanup ..."
72-
config warm_restart disable || /bin/true
76+
result=`timeout 10s config warm_restart disable; if [[ $? == 124 ]]; then echo timeout; else echo "code ($?)"; fi` || /bin/true
77+
debug "Cancel warm-reboot: ${result}"
7378
/sbin/kexec -u || /bin/true
7479
7580
TIMESTAMP=`date +%Y%m%d-%H%M%S`
@@ -113,16 +118,29 @@ function wait_for_pre_shutdown_complete_or_fail()
113118
debug "Waiting for pre-shutdown ..."
114119
TABLE="WARM_RESTART_TABLE|warm-shutdown"
115120
STATE="requesting"
116-
declare -i waitcount;
121+
declare -i waitcount
122+
declare -i retrycount
117123
waitcount=0
124+
retrycount=0
118125
# Wait up to 60 seconds for pre-shutdown to complete
119126
while [[ ${waitcount} -lt 600 ]]; do
120-
STATE=`/usr/bin/redis-cli -n 6 hget "${TABLE}" state`
121-
if [[ x"${STATE}" != x"requesting" ]]; then
127+
# timeout doesn't work with -i option of "docker exec". Therefore we have
128+
# to invoke docker exec directly below.
129+
STATE=`timeout 5s docker exec database redis-cli -n 6 hget "${TABLE}" state; if [[ $? == 124 ]]; then echo "timed out"; fi`
130+
131+
if [[ x"${STATE}" == x"timed out" ]]; then
132+
waitcount+=50
133+
retrycount+=1
134+
debug "Timed out getting pre-shutdown state (${waitcount}) retry count ${retrycount} ..."
135+
if [[ retrycount -gt 2 ]]; then
136+
break
137+
fi
138+
elif [[ x"${STATE}" != x"requesting" ]]; then
122139
break
140+
else
141+
sleep 0.1
142+
waitcount+=1
123143
fi
124-
sleep 0.1
125-
waitcount+=1
126144
done
127145
128146
if [[ x"${STATE}" != x"pre-shutdown-succeeded" ]]; then

0 commit comments

Comments
 (0)