diff --git a/salt/common/tools/sbin/so-common b/salt/common/tools/sbin/so-common index c71e9150c..caa19cd37 100755 --- a/salt/common/tools/sbin/so-common +++ b/salt/common/tools/sbin/so-common @@ -141,6 +141,25 @@ get_random_value() { head -c 5000 /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $length | head -n 1 } +retry() { + maxAttempts=$1 + sleepDelay=$2 + cmd=$3 + attempt=0 + while [[ $attempt -lt $maxAttempts ]]; do + attempt=$((attempt+1)) + logCmd "$cmd" + exitcode=$? + if [[ $exitcode -eq 0 ]]; then + return $exitCode + fi + info "Command failed with exit code $exitcode; will retry in $sleepDelay seconds ($attempt / $maxAttempts)..." + sleep $sleepDelay + done + error "Command continues to fail; giving up." + return 1 +} + wait_for_apt() { local progress_callback=$1 diff --git a/setup/so-functions b/setup/so-functions index 83b5aef3c..b2b7b688c 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1972,7 +1972,7 @@ set_progress_str() { printf '%s\n' \ '----'\ - "$percentage% - ${progress_bar_text^^}"\ + info "$percentage% - ${progress_bar_text^^}"\ "----" >> "$setup_log" 2>&1 } diff --git a/setup/so-setup b/setup/so-setup index 15189746f..28f0bc0bb 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -637,12 +637,12 @@ set_redirect >> $setup_log 2>&1 if [[ $is_minion ]]; then set_progress_str 20 'Accepting Salt key on manager' - accept_salt_key_remote >> $setup_log 2>&1 + retry 20 10 accept_salt_key_remote fi if [[ $is_manager || $is_import || $is_helix ]]; then set_progress_str 20 'Accepting Salt key' - salt-key -ya "$MINION_ID" >> $setup_log 2>&1 + retry 20 10 "salt-key -ya $MINION_ID" fi set_progress_str 21 'Copying minion pillars to manager'