mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-20 05:22:03 +08:00
c5d5c5d1f3
date: 2025-10-24T00:30:59 master commit: 405631baf9685e171a0dd19547cb763f1b163d18
28 lines
511 B
Bash
Executable File
28 lines
511 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
function fail {
|
|
echo $1 >&2
|
|
exit 1
|
|
}
|
|
|
|
function retry {
|
|
local n=1
|
|
local max=3 # 3 retries before failure
|
|
local delay=5 # delay between retries, 5 seconds
|
|
while true; do
|
|
echo "Running command '$@' with retry, attempt $n/$max"
|
|
"$@" && break || {
|
|
if [[ $n -lt $max ]]; then
|
|
((n++))
|
|
sleep $delay;
|
|
else
|
|
fail "The command has failed after $n attempts."
|
|
fi
|
|
}
|
|
done
|
|
}
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
retry "$@"
|
|
fi
|