@@ -53,6 +53,10 @@ Options:
53
53
build the closure on the remote machine instead of locally and copy-closuring it
54
54
* --vm-test
55
55
build the system and test the disk configuration inside a VM without installing it to the target.
56
+ * --ssh-retry-limit <limit>
57
+ set the number of times to retry the ssh connection before giving up
58
+ * --reboot-retry-limit <limit>
59
+ set the number of times to wait for the reboot before giving up.
56
60
USAGE
57
61
}
58
62
@@ -180,6 +184,14 @@ while [[ $# -gt 0 ]]; do
180
184
--vm-test)
181
185
vm_test=y
182
186
;;
187
+ --ssh-retry-limit)
188
+ ssh_retry_limit=$2
189
+ shift
190
+ ;;
191
+ --reboot-retry-limit)
192
+ reboot_retry_limit=$2
193
+ shift
194
+ ;;
183
195
* )
184
196
if [[ -z ${ssh_connection-} ]]; then
185
197
ssh_connection=" $1 "
@@ -192,6 +204,10 @@ while [[ $# -gt 0 ]]; do
192
204
shift
193
205
done
194
206
207
+ # Set default retry limits to -1 (infinite retries)
208
+ ssh_retry_limit=${ssh_retry_limit:- -1}
209
+ reboot_retry_limit=${reboot_retry_limit:- -1}
210
+
195
211
if [[ ${print_build_logs-n} == " y" ]]; then
196
212
nix_options+=(" -L" )
197
213
fi
@@ -302,6 +318,7 @@ ssh_host=$(echo "$ssh_settings" | awk '/^hostname / { print $2 }')
302
318
ssh_port=$( echo " $ssh_settings " | awk ' /^port / { print $2 }' )
303
319
304
320
step Uploading install SSH keys
321
+ retry_count=0
305
322
until
306
323
if [[ -n ${env_password-} ]]; then
307
324
sshpass -e \
@@ -325,7 +342,12 @@ until
325
342
" $ssh_connection "
326
343
fi
327
344
do
328
- sleep 3
345
+ sleep 5
346
+ retry_count=$(( retry_count + 1 ))
347
+ echo " Retrying ssh-copy-id: count $retry_count "
348
+ if [[ $ssh_retry_limit -ne -1 && $retry_count -ge $ssh_retry_limit ]]; then
349
+ abort " Reached ssh retry limit of $ssh_retry_limit "
350
+ fi
329
351
done
330
352
331
353
import_facts () {
421
443
ssh_connection=" root@${ssh_host} "
422
444
423
445
# waiting for machine to become available again
424
- until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
446
+ retry_count=0
447
+ until ssh_ -o ConnectTimeout=10 -- exit 0; do
448
+ sleep 5
449
+ retry_count=$(( retry_count + 1 ))
450
+ echo " Waiting for reboot count $retry_count "
451
+ if [[ $reboot_retry_limit -ne -1 && $retry_count -ge $reboot_retry_limit ]]; then
452
+ abort " Machine didn't come online after reboot connection limit of $reboot_retry_limit retries"
453
+ fi
454
+ done
425
455
fi
426
456
427
457
# Installation will fail if non-root user is used for installer.
0 commit comments