@@ -34,13 +34,14 @@ function showHelpAndExit()
34
34
echo " -f : force execution"
35
35
echo " -r : reboot with /sbin/reboot [default]"
36
36
echo " -k : reboot with /sbin/kexec -e"
37
+ echo " -x : execute script with -x flag"
37
38
38
39
exit 0
39
40
}
40
41
41
42
function parseOptions()
42
43
{
43
- while getopts " vfh?rk " opt; do
44
+ while getopts " vfh?rkx " opt; do
44
45
case ${opt} in
45
46
h )
46
47
showHelpAndExit
@@ -60,6 +61,9 @@ function parseOptions()
60
61
k )
61
62
REBOOT_METHOD=" /sbin/kexec -e"
62
63
;;
64
+ x )
65
+ set -x
66
+ ;;
63
67
esac
64
68
done
65
69
}
@@ -69,7 +73,8 @@ sonic_asic_type=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
69
73
function clear_warm_boot()
70
74
{
71
75
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} "
73
78
/sbin/kexec -u || /bin/true
74
79
75
80
TIMESTAMP=` date +%Y%m%d-%H%M%S`
@@ -113,16 +118,29 @@ function wait_for_pre_shutdown_complete_or_fail()
113
118
debug " Waiting for pre-shutdown ..."
114
119
TABLE=" WARM_RESTART_TABLE|warm-shutdown"
115
120
STATE=" requesting"
116
- declare -i waitcount;
121
+ declare -i waitcount
122
+ declare -i retrycount
117
123
waitcount=0
124
+ retrycount=0
118
125
# Wait up to 60 seconds for pre-shutdown to complete
119
126
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
122
139
break
140
+ else
141
+ sleep 0.1
142
+ waitcount+=1
123
143
fi
124
- sleep 0.1
125
- waitcount+=1
126
144
done
127
145
128
146
if [[ x" ${STATE} " != x" pre-shutdown-succeeded" ]]; then
0 commit comments