Skip to content

fix(installer): keep apt non-interactive so needrestart can't hang installs on Ubuntu 22.04+#212

Merged
LukasWodka merged 1 commit into
developfrom
fix/conntrack-ubuntu-noninteractive
Jun 5, 2026
Merged

fix(installer): keep apt non-interactive so needrestart can't hang installs on Ubuntu 22.04+#212
LukasWodka merged 1 commit into
developfrom
fix/conntrack-ubuntu-noninteractive

Conversation

@LukasWodka
Copy link
Copy Markdown
Contributor

Summary

On Ubuntu 22.04+ (incl. 24.04) the needrestart package hooks apt-get install and opens an interactive "Which services should be restarted?" prompt. -y does not suppress it.

The installer runs apt inside spin_cmd, which redirects stdout/stderr to a log and backgrounds the process. So the prompt is invisible (only the spinner shows) and, being backgrounded, blocks the moment it reads the TTY (SIGTTIN) — the install hangs forever. The reported symptom was the spinner stuck "still pulling conntrack" on a fresh Ubuntu 24.04 host: the package was downloading fine; it was waiting on a hidden prompt.

(The authors already knew "spinners hide prompts" — preflight_sudo warms the sudo cache for exactly this reason — but needrestart/debconf were missed.)

Fix

Pass DEBIAN_FRONTEND=noninteractive + NEEDRESTART_MODE=a through sudo env (sudo resets the environment, so the vars must be set through it) on every apt path the installer drives:

Path File
PM_INSTALL — conntrack / openssl / curl / tar (and nvidia-container-toolkit, which calls $PM_INSTALL) scripts/lib/setup-linux.sh
get.docker.com convenience script (runs apt-get internally) scripts/lib/setup-linux.sh
WSL2 NVIDIA Container Toolkit heredoc — same hidden-prompt class; bounded by the 180 s job timeout but still fails the toolkit install scripts/install-k8s.ps1

Reuses the established sudo env VAR=val pattern already used for install_k3d (#718).

Tests

scripts/tests/setup-linux.bats:

  • new: setup_pm: apt is non-interactive (needrestart/debconf guard) — asserts DEBIAN_FRONTEND=noninteractive, NEEDRESTART_MODE=a, and sudo env in PM_INSTALL.
  • strengthened: the Debian/Ubuntu get.docker.com test now also asserts the non-interactive env.

bats scripts/tests/setup-linux.bats is green for every touched test. Two unrelated tests (Amazon Linux → dnf docker, RHEL clone → docker-ce) fail only on macOS dev machines because of BSD-vs-GNU grep in the /etc/os-release mock; they pass in CI on Linux and are untouched here.

Out of scope / follow-up

  • scripts/lib/gpu-amd.sh:53 (sudo apt-get install … amdgpu-install.deb) is a direct, visible apt-get (not wrapped in spin_cmd), so a needrestart prompt there is annoying but not a silent hang. The same env could be added for consistency in a later pass.
  • scripts/tests/distro-prereqs.sh is a CI-only helper that runs as root in minimal containers (no needrestart) — no exposure.

…stalls on Ubuntu 22.04+

Ubuntu 22.04+ ships needrestart, which hooks `apt-get install` and opens an
interactive "restart services?" prompt that `-y` does not suppress. The
installer runs apt inside spin_cmd (output redirected, process backgrounded),
so the prompt is invisible and blocks on the TTY (SIGTTIN) → the install hangs
forever (reported as the spinner stuck "still pulling conntrack" on Ubuntu 24.04).

Pass DEBIAN_FRONTEND=noninteractive + NEEDRESTART_MODE=a through `sudo env`
(sudo resets the env) on every apt path the installer drives:
- PM_INSTALL: conntrack/openssl/curl/tar (+ nvidia-container-toolkit via $PM_INSTALL)
- get.docker.com convenience script (runs apt-get internally)
- WSL2 NVIDIA Container Toolkit heredoc in install-k8s.ps1 (parity)

Reuses the existing `sudo env VAR=val` pattern (install_k3d, #718). Adds a bats
guard asserting apt stays non-interactive.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@LukasWodka
Copy link
Copy Markdown
Contributor Author

👋 Heads-up — Code review queue is at 18 / 8

Above the WIP limit. The team convention is to review existing PRs before opening new work.

Open PRs currently in Code review (oldest first):

Pull from review before opening new work. (This is a nudge from the kanban WIP check, not a block.)

saadqbal added a commit that referenced this pull request Jun 5, 2026
…g the install (#210)

Stacked on #212 (the needrestart non-interactive fix). This adds the lock
dimension #212 doesn't cover: on a freshly-booted Ubuntu, apt-daily /
unattended-upgrades hold the dpkg lock and apt-get waits on it forever —
and spin_cmd hides apt's "Waiting for cache lock" line, so it looks frozen.

- setup_pm: add -o DPkg::Lock::Timeout=600 to the apt update/install commands
  so the wait is bounded and fails with a clear error instead of hanging.
- add apt_wait_for_lock: a visible, bounded "Waiting for background system
  updates to finish…" step before the docker / system-deps installs.
- bats: assert the apt commands carry the lock timeout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saadqbal
Copy link
Copy Markdown
Contributor

saadqbal commented Jun 5, 2026

Heads-up @LukasWodka: #211 was chasing the same Installing conntrack… hang but via a different root cause — the dpkg lock held by apt-daily/unattended-upgrades on a freshly-booted host (no DPkg::Lock::Timeout, so apt waits forever and spin_cmd hides the Waiting for cache lock line).

Our two PRs overlapped on the non-interactive sudo env edit, so rather than ship a duplicated/conflicting change I've rebased #211 onto this branch and trimmed it to only the lock dimension (DPkg::Lock::Timeout + a visible apt_wait_for_lock step). #211's diff is now purely additive on top of yours and keeps your non-interactive env exactly as-is.

Suggested merge order: this PR (#212) into develop first, then I'll retarget #211 to develop (applies cleanly) and it can go in right after. The two are complementary — yours fixes the hidden-prompt hang, #211 the lock-wait hang.

@LukasWodka LukasWodka merged commit 7f0d0fb into develop Jun 5, 2026
22 checks passed
saadqbal added a commit that referenced this pull request Jun 5, 2026
…g the install (#210)

Stacked on #212 (the needrestart non-interactive fix). This adds the lock
dimension #212 doesn't cover: on a freshly-booted Ubuntu, apt-daily /
unattended-upgrades hold the dpkg lock and apt-get waits on it forever —
and spin_cmd hides apt's "Waiting for cache lock" line, so it looks frozen.

- setup_pm: add -o DPkg::Lock::Timeout=600 to the apt update/install commands
  so the wait is bounded and fails with a clear error instead of hanging.
- add apt_wait_for_lock: a visible, bounded "Waiting for background system
  updates to finish…" step before the docker / system-deps installs.
- bats: assert the apt commands carry the lock timeout.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants