27
27
postKexecSshPort=22
28
28
buildOnRemote=n
29
29
envPassword=
30
+ sshRetryLimit=-1
31
+ rebootRetryLimit=-1
30
32
31
33
declare -A diskEncryptionKeys
32
34
declare -a nixCopyOptions
@@ -86,6 +88,10 @@ Options:
86
88
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
87
89
install: install the system
88
90
reboot: reboot the machine
91
+ * --ssh-retry-limit <limit>
92
+ set the number of times to retry the ssh connection before giving up
93
+ * --reboot-retry-limit <limit>
94
+ set the number of times to wait for the reboot before giving up.
89
95
USAGE
90
96
}
91
97
@@ -213,6 +219,14 @@ parseArgs() {
213
219
--vm-test)
214
220
vmTest=y
215
221
;;
222
+ --ssh-retry-limit)
223
+ sshRetryLimit=$2
224
+ shift
225
+ ;;
226
+ --reboot-retry-limit)
227
+ rebootRetryLimit=$2
228
+ shift
229
+ ;;
216
230
* )
217
231
if [[ -z ${sshConnection-} ]]; then
218
232
sshConnection=" $1 "
@@ -316,6 +330,7 @@ uploadSshKey() {
316
330
fi
317
331
318
332
step Uploading install SSH keys
333
+ local retryCount=0
319
334
until
320
335
if [[ -n ${envPassword} ]]; then
321
336
sshpass -e \
@@ -339,7 +354,11 @@ uploadSshKey() {
339
354
" $sshConnection "
340
355
fi
341
356
do
342
- sleep 3
357
+ sleep 5
358
+ retryCount=$(( retryCount + 1 ))
359
+ if [[ $sshRetryLimit -ne -1 ]] && [[ $retryCount -ge $sshRetryLimit ]]; then
360
+ abort " Reached ssh retry limit of $sshRetryLimit "
361
+ fi
343
362
done
344
363
}
345
364
@@ -581,7 +600,14 @@ main() {
581
600
582
601
if [[ ${phases[reboot]-} == 1 ]]; then
583
602
step Waiting for the machine to become unreachable due to reboot
584
- while runSshTimeout -- exit 0; do sleep 1; done
603
+ retryCount=0
604
+ until ssh_ -o ConnectTimeout=10 -- exit 0; do
605
+ sleep 5
606
+ retryCount=$(( retryCount + 1 ))
607
+ if [[ $rebootRetryLimit -ne -1 ]] && [[ $retryCount -ge $rebootRetryLimit ]]; then
608
+ abort " Machine didn't come online after reboot connection limit of $rebootRetryLimit retries"
609
+ fi
610
+ done
585
611
fi
586
612
587
613
step " Done!"
0 commit comments