@@ -53,6 +53,10 @@ Options:
5353 build the closure on the remote machine instead of locally and copy-closuring it
5454* --vm-test
5555 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.
5660USAGE
5761}
5862
@@ -180,6 +184,14 @@ while [[ $# -gt 0 ]]; do
180184 --vm-test)
181185 vm_test=y
182186 ;;
187+ --ssh-retry-limit)
188+ ssh_retry_limit=$2
189+ shift
190+ ;;
191+ --reboot-retry-limit)
192+ reboot_retry_limit=$2
193+ shift
194+ ;;
183195 * )
184196 if [[ -z ${ssh_connection-} ]]; then
185197 ssh_connection=" $1 "
@@ -192,6 +204,10 @@ while [[ $# -gt 0 ]]; do
192204 shift
193205done
194206
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+
195211if [[ ${print_build_logs-n} == " y" ]]; then
196212 nix_options+=(" -L" )
197213fi
@@ -302,6 +318,7 @@ ssh_host=$(echo "$ssh_settings" | awk '/^hostname / { print $2 }')
302318ssh_port=$( echo " $ssh_settings " | awk ' /^port / { print $2 }' )
303319
304320step Uploading install SSH keys
321+ retry_count=0
305322until
306323 if [[ -n ${env_password-} ]]; then
307324 sshpass -e \
@@ -325,7 +342,12 @@ until
325342 " $ssh_connection "
326343 fi
327344do
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
329351done
330352
331353import_facts () {
421443 ssh_connection=" root@${ssh_host} "
422444
423445 # 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
425455fi
426456
427457# Installation will fail if non-root user is used for installer.
0 commit comments