File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88set -euo pipefail
99
10+ apt_background_procs () {
11+ # Ignore unattended-upgrade-shutdown --wait-for-signal. That service can stay
12+ # running while apt is actually idle and causes false "busy" detections.
13+ pgrep -f -a ' (apt.systemd.daily|apt-get|dpkg|unattended-upgrade)' 2> /dev/null \
14+ | grep -v ' unattended-upgrade-shutdown --wait-for-signal' || true
15+ }
16+
1017wait_for_apt_idle () {
1118 # Fresh Ubuntu droplets may run unattended-upgrades on first boot.
12- # Wait until apt/dpkg background processes are gone.
19+ # Wait until real apt/dpkg workers are gone.
1320 for _ in $( seq 1 90) ; do
14- if ! pgrep -f -a ' (apt|apt-get|dpkg|unattended-upgrade) ' > /dev/null 2>&1 ; then
21+ if [ -z " $( apt_background_procs ) " ] ; then
1522 return 0
1623 fi
1724 sleep 2
@@ -24,16 +31,19 @@ wait_for_apt_idle || echo " continuing after timeout; will retry apt commands i
2431
2532echo " === [Ubuntu] Installing git (needed to init test repo) ==="
2633for attempt in $( seq 1 8) ; do
27- if apt-get update -qq && apt-get install -y -qq git 2>&1 | tail -1; then
34+ if apt-get -o DPkg::Lock::Timeout=120 update -qq \
35+ && apt-get -o DPkg::Lock::Timeout=120 install -y -qq git 2>&1 | tail -1; then
2836 break
2937 fi
3038
3139 if [ " $attempt " -eq 8 ]; then
3240 echo " apt failed after $attempt attempts" >&2
41+ apt_background_procs >&2 || true
3342 exit 1
3443 fi
3544
3645 echo " apt busy (attempt $attempt /8), retrying in 5s..."
46+ apt_background_procs || true
3747 wait_for_apt_idle || true
3848 sleep 5
3949done
Original file line number Diff line number Diff line change @@ -142,19 +142,40 @@ info "Admin user: ${BOLD}$ADMIN_USER${RESET} ($ADMIN_HOME)"
142142
143143header " Prerequisites"
144144
145+ apt_background_procs_ubuntu () {
146+ # Ignore unattended-upgrade-shutdown --wait-for-signal. It can remain active
147+ # with no apt/dpkg lock contention and causes false waits on fresh Ubuntu VMs.
148+ pgrep -f -a ' (apt.systemd.daily|apt-get|dpkg|unattended-upgrade)' 2> /dev/null \
149+ | grep -v ' unattended-upgrade-shutdown --wait-for-signal' || true
150+ }
151+
145152install_prereqs_ubuntu () {
146153 # Wait for unattended-upgrades (common on fresh VMs)
147- if pgrep -f -a ' (apt|apt-get|dpkg|unattended-upgrade) ' > /dev/null 2>&1 ; then
154+ if [ -n " $( apt_background_procs_ubuntu ) " ] ; then
148155 info " Waiting for background apt to finish..."
149156 for _ in $( seq 1 60) ; do
150- if ! pgrep -f -a ' (apt|apt-get|dpkg|unattended-upgrade) ' > /dev/null 2>&1 ; then
157+ if [ -z " $( apt_background_procs_ubuntu ) " ] ; then
151158 break
152159 fi
153160 sleep 2
154161 done
155162 fi
156- apt-get update -qq
157- apt-get install -y -qq git curl tmux iptables docker.io gh sudo 2>&1 | tail -3
163+
164+ for attempt in $( seq 1 5) ; do
165+ if DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=120 update -qq \
166+ && DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::Lock::Timeout=120 install -y -qq git curl tmux iptables docker.io gh sudo 2>&1 | tail -3; then
167+ return 0
168+ fi
169+
170+ if [ " $attempt " -eq 5 ]; then
171+ err " apt failed after $attempt attempts"
172+ apt_background_procs_ubuntu >&2 || true
173+ return 1
174+ fi
175+
176+ warn " apt busy (attempt $attempt /5), retrying in 5s..."
177+ sleep 5
178+ done
158179}
159180
160181install_prereqs_arch () {
You can’t perform that action at this time.
0 commit comments