From d7891f7cf1874b65519414766cff90cf20955697 Mon Sep 17 00:00:00 2001 From: tieuanhquoc <54701784+tieuanhquoc@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:25:29 +0700 Subject: [PATCH 1/2] fix: enforce lowered disk limit, keep attached output, show UI on reopen and quit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Disk limit: the VM disk only ever grew, so lowering the limit (64 → 16 GB) was ignored. Apply & Restart now stops Docker, shrinks the disk offline in the builder VM (e2fsck, resize2fs with headroom, GPT rewritten for the new size), truncates the image and starts Docker again. An APFS clone is kept until it succeeds and put back on failure or an interrupted run; data that does not fit is refused with a limit that would fit, and the setting goes back to the real disk size. `DockZ shrink-disk` does the same headless. Monitor shows used space against the limit (80% / 95% colours) plus the Mac's free space. - Attached output: the guest's socat relays used the default -t 0.5, so a docker CLI half-close cut hijacked streams after half a second (`docker run` without -d lost everything printed later). All relays now keep the other direction open. Guest rootfs files baked into disk.img never got such fixes, so every boot now syncs the app's copy into the VM (boot-path files excluded) and restarts changed services. - Reopening DockZ while its menu bar icon is hidden shows the dashboard; a user launch opens it, Launch at Login stays quiet. - Quitting shows a "Shutting down DockZ…" window listing what is stopped. Tests: 321 checks pass (61 new). Verified on a throwaway data root: new disks are created at the limit; shrink 24 → 8 GB refused with the disk unchanged, 24 → 16 GB done in 18 s with file checksums intact after boot; an old-image VM got the new agent on its first boot and `echo start; sleep 6; echo end`, exec, piped stdin and logs -f all stream fully. The output fix was also confirmed on a real install. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 27 ++++ README.md | 2 +- README.vi.md | 2 +- guest/rootfs/etc/init.d/dockz-agent | 16 ++- guest/shrink-disk-inside-vm.sh | 85 ++++++++++++ sources/dockz/app-delegate.swift | 122 +++++++++++++++-- sources/dockz/app-main.swift | 3 + sources/dockz/dashboard-store.swift | 4 + .../dockz/dashboard-window-controller.swift | 2 + sources/dockz/disk-limit-policy.swift | 111 +++++++++++++++ sources/dockz/disk-shrink-cli.swift | 41 ++++++ sources/dockz/disk-shrinker.swift | 126 ++++++++++++++++++ sources/dockz/disk-usage.swift | 7 + sources/dockz/guest-rootfs-sync.swift | 107 +++++++++++++++ sources/dockz/image-builder-cli.swift | 6 +- sources/dockz/launch-intent.swift | 28 ++++ sources/dockz/monitor-store.swift | 9 +- sources/dockz/monitor-view.swift | 25 +++- sources/dockz/shutdown-progress-window.swift | 117 ++++++++++++++++ sources/dockz/status-menu-controller.swift | 9 +- sources/dockz/test-runner-disk-limit.swift | 82 ++++++++++++ sources/dockz/test-runner-guest-sync.swift | 57 ++++++++ sources/dockz/test-runner-robustness.swift | 33 ++++- sources/dockz/test-runner.swift | 2 + sources/dockz/vm-settings-view.swift | 49 +++++-- 25 files changed, 1030 insertions(+), 42 deletions(-) create mode 100644 guest/shrink-disk-inside-vm.sh create mode 100644 sources/dockz/disk-limit-policy.swift create mode 100644 sources/dockz/disk-shrink-cli.swift create mode 100644 sources/dockz/disk-shrinker.swift create mode 100644 sources/dockz/guest-rootfs-sync.swift create mode 100644 sources/dockz/launch-intent.swift create mode 100644 sources/dockz/shutdown-progress-window.swift create mode 100644 sources/dockz/test-runner-disk-limit.swift create mode 100644 sources/dockz/test-runner-guest-sync.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b7b945..0e0dd97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,33 @@ are taken from its section here. ## [Unreleased] +### Changed +- Quitting DockZ (menu bar Quit, ⌘Q, the Dock, or logout) now shows a "Shutting down + DockZ…" window listing the Docker engine and Linux machines being stopped, with a check + as each one finishes, instead of seeming frozen for the seconds a clean VM shutdown takes. + +- Monitor's disk card shows space used against the disk limit (orange from 80%, red from + 95%) instead of against the filesystem size, with how much space is free on the Mac. + Settings shows the Mac's free space too. + +### Fixed +- The disk limit is now enforced when it is lowered. Before, the VM disk only ever grew, so + a disk created at 64 GB kept using up to 64 GB after the limit was set to 16 GB. Apply & + Restart now stops Docker, shrinks the disk offline to the new limit and starts Docker + again. A safety copy is kept until the shrink succeeds. If the data does not fit, the + disk is left as it is and the message says which limit would fit. `DockZ shrink-disk` + does the same from the terminal while DockZ is closed. +- `docker run` (without `-d`), `docker exec` and other attached commands lost any output + printed more than half a second after they started: `sh -c 'echo start; sleep 3; echo + end'` showed only "start". The VM's socket relay closed the stream half a second after + the docker CLI finished sending input. Existing VMs get the fix at their next start: DockZ + now brings the VM's own DockZ service files up to date with the app on every boot (boot + files excluded), so later fixes to them reach existing disks too. +- Opening DockZ while its menu bar icon is hidden (a crowded menu bar or the notch) did + nothing, so the app looked frozen. Opening it again from Finder, Spotlight or Launchpad + now always shows the dashboard (restoring it if minimised), and a launch you start + yourself opens it too; only Launch at Login still starts quietly in the menu bar. + ## [0.2.2] - 2026-10-07 ### Added diff --git a/README.md b/README.md index 51ad3f1..3a429b3 100644 --- a/README.md +++ b/README.md @@ -337,7 +337,7 @@ Settings): | File / dir | Purpose | | -------------- | -------------------------------------------------------------- | -| `disk.img` | VM disk (sparse; grows up to the configured disk limit) | +| `disk.img` | VM disk (sparse; sized to the disk limit — lowering the limit shrinks it on Apply & Restart, or with `DockZ shrink-disk` while DockZ is closed) | | `docker.sock` | Host-side Docker socket (bridged to the guest over vsock) | | `console.log` | Guest serial console — first stop for boot debugging | | `host.log` | Host-side VM lifecycle log (state changes, stop/poweroff path) | diff --git a/README.vi.md b/README.vi.md index 17b0aa2..e88bb90 100644 --- a/README.vi.md +++ b/README.vi.md @@ -337,7 +337,7 @@ Settings): | Tệp / thư mục | Mục đích | | -------------- | -------------------------------------------------------------- | -| `disk.img` | Ổ đĩa VM (sparse; tăng dần tới giới hạn dung lượng đĩa đã cấu hình) | +| `disk.img` | Ổ đĩa VM (sparse; đúng bằng giới hạn dung lượng — hạ giới hạn thì Apply & Restart sẽ thu nhỏ đĩa, hoặc chạy `DockZ shrink-disk` khi DockZ đang tắt) | | `docker.sock` | Docker socket phía host (bắc cầu tới guest qua vsock) | | `console.log` | Serial console của guest — nơi đầu tiên cần xem khi debug quá trình boot | | `host.log` | Log vòng đời VM phía host (đổi trạng thái, đường stop/poweroff) | diff --git a/guest/rootfs/etc/init.d/dockz-agent b/guest/rootfs/etc/init.d/dockz-agent index ef60778..52c4778 100644 --- a/guest/rootfs/etc/init.d/dockz-agent +++ b/guest/rootfs/etc/init.d/dockz-agent @@ -7,24 +7,32 @@ depend() { use net docker } +# socat ends a connection 0.5 s (its default -t) after either side half-closes. +# The docker CLI half-closes its side of a hijacked stream right after +# attaching (`docker run` without -i), so output arriving later was dropped: +# `sh -c 'echo start; sleep 3; echo end'` printed only "start". Keep the other +# direction open until it ends by itself. 2147483 s (~24 days) is the largest +# value whose milliseconds still fit a 32-bit int in socat's poll timeout. +RELAY_OPTS="-t 2147483" + start() { ebegin "Starting dockz vsock agents" modprobe virtio_vsock 2>/dev/null || true start-stop-daemon --start --background --make-pidfile \ --pidfile /run/dockz-proxy.pid \ - --exec /usr/bin/socat -- \ + --exec /usr/bin/socat -- $RELAY_OPTS \ VSOCK-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock start-stop-daemon --start --background --make-pidfile \ --pidfile /run/dockz-ip.pid \ - --exec /usr/bin/socat -- \ + --exec /usr/bin/socat -- $RELAY_OPTS \ VSOCK-LISTEN:2376,reuseaddr,fork EXEC:/usr/local/bin/dockz-print-ip start-stop-daemon --start --background --make-pidfile \ --pidfile /run/dockz-power.pid \ - --exec /usr/bin/socat -- \ + --exec /usr/bin/socat -- $RELAY_OPTS \ VSOCK-LISTEN:2377,reuseaddr,fork EXEC:/usr/local/bin/dockz-poweroff start-stop-daemon --start --background --make-pidfile \ --pidfile /run/dockz-shell.pid \ - --exec /usr/bin/socat -- \ + --exec /usr/bin/socat -- $RELAY_OPTS \ VSOCK-LISTEN:2378,reuseaddr,fork EXEC:'/bin/sh -i',stderr eend $? } diff --git a/guest/shrink-disk-inside-vm.sh b/guest/shrink-disk-inside-vm.sh new file mode 100644 index 0000000..2815016 --- /dev/null +++ b/guest/shrink-disk-inside-vm.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# Runs INSIDE the Alpine netboot builder VM, driven over the serial console by +# DiskShrinker (sources/dockz/disk-shrinker.swift). Shrinks an existing DockZ +# disk (GPT: vda1 ESP, vda2 ext4 root — the last partition) so the host can +# truncate the image to TARGET_SECTORS. ext4 can only be shrunk unmounted, +# which is why this runs here and not in the guest itself. +# +# Env: TARGET_SECTORS — new disk size in 512-byte sectors +# HEADROOM_BYTES — free space the shrunk filesystem must still have +# +# Markers for the host (one line each): +# DOCKZ-SHRINK-STEP: