Skip to content

Commit c398e30

Browse files
committed
chore: add retries
1 parent a19777b commit c398e30

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

run_once_install-packages.sh.tmpl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,30 @@ sudo pacman -S --needed --noconfirm \
2727
# Ubuntu / Debian
2828
export DEBIAN_FRONTEND=noninteractive
2929

30+
# Retry wrapper for apt commands that may fail due to lock contention
31+
# (e.g. when Coder startup scripts run apt concurrently)
32+
retry_apt() {
33+
local attempt=1
34+
local max_attempts=30
35+
while [ "$attempt" -le "$max_attempts" ]; do
36+
if "$@"; then
37+
return 0
38+
fi
39+
echo "apt command failed (attempt $attempt/$max_attempts), retrying in 5s..."
40+
attempt=$((attempt + 1))
41+
sleep 5
42+
done
43+
echo "apt command failed after $max_attempts attempts"
44+
return 1
45+
}
46+
3047
# Add fish PPA for latest version
3148
if ! command -v fish >/dev/null 2>&1; then
32-
sudo apt-add-repository -y ppa:fish-shell/release-3
49+
retry_apt sudo apt-add-repository -y ppa:fish-shell/release-3
3350
fi
3451

35-
sudo apt-get update -qq
36-
sudo apt-get install -y -qq \
52+
retry_apt sudo apt-get update -qq
53+
retry_apt sudo apt-get install -y -qq \
3754
bat \
3855
direnv \
3956
fish \

0 commit comments

Comments
 (0)