@@ -47,7 +47,7 @@ function error()
47
47
function debug()
48
48
{
49
49
if [[ x" ${VERBOSE} " == x" yes" ]]; then
50
- echo ` date` $@
50
+ echo $( date) $@
51
51
fi
52
52
logger " $@ "
53
53
}
@@ -128,10 +128,10 @@ function clear_warm_boot()
128
128
{
129
129
common_clear
130
130
131
- result=` timeout 10s config warm_restart disable; if [[ $? == 124 ]]; then echo timeout; else echo " code ($? )" ; fi` || /bin/true
131
+ result=$( timeout 10s config warm_restart disable; res= $? ; if [[ $res == 124 ]]; then echo timeout; else echo " code ($res )" ; fi) || /bin/true
132
132
debug " Cancel warm-reboot: ${result} "
133
133
134
- TIMESTAMP=` date +%Y%m%d-%H%M%S`
134
+ TIMESTAMP=$( date +%Y%m%d-%H%M%S)
135
135
if [[ -f ${WARM_DIR} /${REDIS_FILE} ]]; then
136
136
mv -f ${WARM_DIR} /${REDIS_FILE} ${WARM_DIR} /${REDIS_FILE} .${TIMESTAMP} || /bin/true
137
137
fi
@@ -155,7 +155,7 @@ function initialize_pre_shutdown()
155
155
{
156
156
debug " Initialize pre-shutdown ..."
157
157
TABLE=" WARM_RESTART_TABLE|warm-shutdown"
158
- RESTORE_COUNT=` sonic-db-cli STATE_DB hget " ${TABLE} " restore_count`
158
+ RESTORE_COUNT=$( sonic-db-cli STATE_DB hget " ${TABLE} " restore_count)
159
159
if [[ -z " $RESTORE_COUNT " ]]; then
160
160
sonic-db-cli STATE_DB hset " ${TABLE} " " restore_count" " 0" > /dev/null
161
161
fi
@@ -165,9 +165,10 @@ function initialize_pre_shutdown()
165
165
function request_pre_shutdown()
166
166
{
167
167
debug " Requesting pre-shutdown ..."
168
- /usr/bin/docker exec -i syncd /usr/bin/syncd_request_shutdown --pre & > /dev/null || {
168
+ STATE=$( timeout 5s docker exec syncd /usr/bin/syncd_request_shutdown --pre & > /dev/null; if [[ $? == 124 ]]; then echo " timed out" ; fi)
169
+ if [[ x" ${STATE} " == x" timed out" ]]; then
169
170
error " Failed to request pre-shutdown"
170
- }
171
+ fi
171
172
}
172
173
173
174
function recover_issu_bank_file()
@@ -205,33 +206,33 @@ function wait_for_pre_shutdown_complete_or_fail()
205
206
STATE=" requesting"
206
207
declare -i waitcount
207
208
declare -i retrycount
208
- waitcount=0
209
209
retrycount=0
210
+ start_time=$SECONDS
211
+ elapsed_time=$(( $SECONDS - $start_time ))
210
212
# Wait up to 60 seconds for pre-shutdown to complete
211
- while [[ ${waitcount } -lt 600 ]]; do
213
+ while [[ ${elapsed_time } -lt 60 ]]; do
212
214
# timeout doesn't work with -i option of "docker exec". Therefore we have
213
215
# to invoke docker exec directly below.
214
- STATE=` timeout 5s sonic-db-cli STATE_DB hget " ${TABLE} " state; if [[ $? == 124 ]]; then echo " timed out" ; fi`
216
+ STATE=$( timeout 5s sonic-db-cli STATE_DB hget " ${TABLE} " state; if [[ $? == 124 ]]; then echo " timed out" ; fi)
215
217
216
218
if [[ x" ${STATE} " == x" timed out" ]]; then
217
- waitcount+=50
218
219
retrycount+=1
219
- debug " Timed out getting pre-shutdown state ( ${waitcount} ) retry count ${retrycount} ..."
220
+ debug " Timed out getting pre-shutdown state, retry count ${retrycount} ..."
220
221
if [[ retrycount -gt 2 ]]; then
221
222
break
222
223
fi
223
224
elif [[ x" ${STATE} " != x" requesting" ]]; then
224
225
break
225
226
else
226
227
sleep 0.1
227
- waitcount+=1
228
228
fi
229
+ elapsed_time=$(( $SECONDS - $start_time ))
229
230
done
230
231
231
232
if [[ x" ${STATE} " != x" pre-shutdown-succeeded" ]]; then
232
- debug " Syncd pre-shutdown failed: ${STATE} ..."
233
+ debug " Syncd pre-shutdown failed, state : ${STATE} ..."
233
234
else
234
- debug " Pre-shutdown succeeded ..."
235
+ debug " Pre-shutdown succeeded, state: ${STATE} ..."
235
236
fi
236
237
}
237
238
@@ -259,7 +260,10 @@ function backup_database()
259
260
260
261
# Dump redis content to a file 'dump.rdb' in warmboot directory
261
262
docker cp database:/var/lib/$target_db_inst /$REDIS_FILE $WARM_DIR
262
- docker exec -i database rm /var/lib/$target_db_inst /$REDIS_FILE
263
+ STATE=$( timeout 5s docker exec database rm /var/lib/$target_db_inst /$REDIS_FILE ; if [[ $? == 124 ]]; then echo " timed out" ; fi)
264
+ if [[ x" ${STATE} " == x" timed out" ]]; then
265
+ error " Timed out during attempting to remove Redis dump file from database container"
266
+ fi
263
267
}
264
268
265
269
function setup_control_plane_assistant()
@@ -309,10 +313,23 @@ function setup_reboot_variables()
309
313
INITRD=$( echo $KERNEL_IMAGE | sed ' s/vmlinuz/initrd.img/g' )
310
314
}
311
315
316
+ function check_docker_exec()
317
+ {
318
+ containers=" radv bgp lldp swss database teamd syncd"
319
+ for container in $containers ; do
320
+ STATE=$( timeout 1s docker exec $container echo " success" ; if [[ $? == 124 ]]; then echo " timed out" ; fi)
321
+ if [[ x" ${STATE} " == x" timed out" ]]; then
322
+ error " Docker exec on $container timedout"
323
+ exit " ${EXIT_FAILURE} "
324
+ fi
325
+ done
326
+ }
327
+
312
328
function reboot_pre_check()
313
329
{
330
+ check_docker_exec
314
331
# Make sure that the file system is normal: read-write able
315
- filename=" /host/test-` date +%Y%m%d-%H%M%S` "
332
+ filename=" /host/test-$( date +%Y%m%d-%H%M%S) "
316
333
if [[ ! -f ${filename} ]]; then
317
334
touch ${filename}
318
335
fi
541
558
# service will go down and we cannot recover from it.
542
559
set +e
543
560
561
+ # disable trap-handlers which were set before
562
+ trap ' ' EXIT HUP INT QUIT TERM KILL ABRT ALRM
563
+
544
564
if [ -x ${LOG_SSD_HEALTH} ]; then
545
565
debug " Collecting logs to check ssd health before ${REBOOT_TYPE} ..."
546
566
${LOG_SSD_HEALTH}
0 commit comments