Skip to content

Commit 12714ec

Browse files
committed
Timeout: add seperate flags for reboot and ssh timeout
1 parent 1933f2e commit 12714ec

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/nixos-anywhere.sh

+32-2
Original file line numberDiff line numberDiff line change
@@ -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.
5660
USAGE
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
193205
done
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+
195211
if [[ ${print_build_logs-n} == "y" ]]; then
196212
nix_options+=("-L")
197213
fi
@@ -302,6 +318,7 @@ ssh_host=$(echo "$ssh_settings" | awk '/^hostname / { print $2 }')
302318
ssh_port=$(echo "$ssh_settings" | awk '/^port / { print $2 }')
303319

304320
step Uploading install SSH keys
321+
retry_count=0
305322
until
306323
if [[ -n ${env_password-} ]]; then
307324
sshpass -e \
@@ -325,7 +342,12 @@ until
325342
"$ssh_connection"
326343
fi
327344
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
329351
done
330352

331353
import_facts() {
@@ -421,7 +443,15 @@ SSH
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
425455
fi
426456

427457
# Installation will fail if non-root user is used for installer.

0 commit comments

Comments
 (0)