Skip to content

Commit 04c15ed

Browse files
chapterjasonclaude
andcommitted
Harden web-shell prereq install against transient apt failures
The apt-get update/install calls had no error handling, so dpkg-lock contention with other startup scripts or a flaky network left dtach silently uninstalled and web-shell broke on first session. Retry up to 3 times with backoff, and verify dtach is on PATH before launching web-shell so failures surface immediately. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1860452 commit 04c15ed

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

terraform/web-shell/run.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,31 @@ for pkg in dtach build-essential python3; do
3131
done
3232
if [ $${#need[@]} -gt 0 ]; then
3333
printf "$${BOLD}Installing prereqs: $${need[*]}$${RESET}\n"
34-
sudo apt-get update
35-
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$${need[@]}"
34+
# Retry on transient apt failures: dpkg-lock contention when other startup
35+
# scripts run apt in parallel, network flakes on apt-get update, mirror
36+
# hiccups. Exit codes were previously unchecked, so failures silently left
37+
# dtach missing and web-shell broke on first session.
38+
installed=0
39+
for attempt in 1 2 3; do
40+
if sudo apt-get update && \
41+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "$${need[@]}"; then
42+
installed=1
43+
break
44+
fi
45+
echo "apt-get attempt $${attempt} failed; retrying..." >&2
46+
sleep $$((attempt * 2))
47+
done
48+
if [ "$${installed}" -ne 1 ]; then
49+
echo "Failed to install prereqs after 3 attempts: $${need[*]}" >&2
50+
exit 1
51+
fi
52+
fi
53+
54+
# dtach is load-bearing — web-shell's session survival across disconnects
55+
# depends on it. Fail loud rather than starting web-shell without it.
56+
if ! command -v dtach >/dev/null 2>&1; then
57+
echo "dtach missing after install step; aborting." >&2
58+
exit 1
3659
fi
3760

3861
# Install or upgrade web-shell if the installed version doesn't match.

0 commit comments

Comments
 (0)