R-179: the uninstall removes the NAS network-storage units

Units carrying the agent's network-storage marker (mnt-*.automount first, then mnt-*.mount) are
disabled --now, reset-failed and removed before the drive umount loop; a share that will not stop is
not forced — its unit is kept and named in KEPT with the commands. Enrolled-drive and foreign units
are never touched. scripts/test_hostinstall.py: test_net_units_* (5).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
2026-10-05 21:21:46 +02:00
parent 7f3944eff9
commit c11d4fbf2e
2 changed files with 141 additions and 2 deletions
+45
View File
@@ -843,6 +843,9 @@ _uninstall_statement() {
echo " - break-glass watchdog + OOB artifacts (where present); guest-hook snippet; dnsmasq snippets; the mkfs, pbs-apply,"
echo " backup-target-apply, os-apply and priv-apply wrappers; the crash guard; the config-bundle record"
echo " - pveum: the Felhom roles/user/token/scoped ACL$( $pool_removed && printf '; the emptied %s pool' "$PVE_POOL")"
if (( ${#_NET_UNITS_REMOVED[@]} > 0 )); then
echo " - the network-share (NAS) mount units: ${_NET_UNITS_REMOVED[*]} (the data stays on the NAS)"
fi
echo " - the install state file"
if $REMOVE_GOLDEN; then echo " - the golden vzdump (--remove-golden)"; fi
else
@@ -850,6 +853,10 @@ _uninstall_statement() {
fi
echo " KEPT (lives on deliberately — remove/rotate these out-of-band if the customer is leaving):"
if [[ "$scope" == "full" ]]; then
if (( ${#_NET_UNITS_BUSY[@]} > 0 )); then
echo " - network-share unit(s) that would not stop (busy, not forced): ${_NET_UNITS_BUSY[*]} — once free:"
echo " systemctl disable --now -- <unit>; rm $NET_UNIT_DIR/<unit>; systemctl daemon-reload"
fi
echo " - the enrolled drives + ALL data under /mnt/felhom-drives — unmounted only, NEVER wiped;"
if [[ ${#_busy_mounts[@]} -gt 0 ]]; then
echo " physically removable now, EXCEPT still mounted (busy — stop the apps and retry): ${_busy_mounts[*]}"
@@ -1058,6 +1065,42 @@ _teardown_wg_tunnel() {
return 0
}
# _remove_network_storage_units — the NAS network-storage .automount/.mount pairs the agent writes (R-179).
#
# A box that ever had a network share kept `mnt-felhom\x2ddrives-<share>.{mount,automount}` after a full
# uninstall, the automount in `failed` state and the parent bind still mounted (demo-hp 2026-08-03). Only
# units carrying the agent's network-storage marker are touched (felhom-agent internal/storage/netmount.go
# netUnitMarker) — never an enrolled drive's unit, never anyone else's. Automounts first (else they
# re-trigger the mount), then mounts. A share that will not stop is NOT forced: it is named and its unit
# kept. Sets _NET_UNITS_REMOVED / _NET_UNITS_BUSY. Pinned by scripts/test_hostinstall.py (test_net_units_*).
NET_UNIT_DIR="/etc/systemd/system"
NET_UNIT_MARKER="Managed by felhom-agent (network storage)"
_NET_UNITS_REMOVED=()
_NET_UNITS_BUSY=()
_remove_network_storage_units() {
local kind f unit
for kind in automount mount; do
for f in "$NET_UNIT_DIR"/mnt-*."$kind"; do
[[ -f "$f" ]] || continue
grep -qF "$NET_UNIT_MARKER" "$f" 2>/dev/null || continue
unit=$(basename "$f")
run systemctl disable --now -- "$unit" 2>/dev/null || true
if ! $DRY_RUN && systemctl is-active --quiet -- "$unit" 2>/dev/null; then
log_warn " network share unit $unit will not stop (busy) — NOT forcing; its unit file is kept (named in KEPT below)."
_NET_UNITS_BUSY+=("$unit")
continue
fi
run systemctl reset-failed -- "$unit" 2>/dev/null || true
run rm -f "$f"
_NET_UNITS_REMOVED+=("$unit")
done
done
if (( ${#_NET_UNITS_REMOVED[@]} > 0 )); then
log_success " removed ${#_NET_UNITS_REMOVED[@]} network-storage unit(s): ${_NET_UNITS_REMOVED[*]}"
fi
return 0
}
run_uninstall() {
log_step "UNINSTALL — local host teardown"
@@ -1260,6 +1303,8 @@ run_uninstall() {
fi
if [[ -f /etc/systemd/system/felhom-shared-parent.service ]]; then run rm -f /etc/systemd/system/felhom-shared-parent.service; else log_skip " felhom-shared-parent.service already absent"; fi
if [[ -f /usr/local/sbin/felhom-shared-parent.sh ]]; then run rm -f /usr/local/sbin/felhom-shared-parent.sh; fi
# R-179: the NAS shares' units go BEFORE the umount loop below, so a stopped share is not "busy".
_remove_network_storage_units
run systemctl daemon-reload
# GL-4: unmount every enrolled/network drive mounted UNDER /mnt/felhom-drives (deepest first)
# BEFORE the root self-bind. Plain umount ONLY — NEVER -l/-f: a lazy/forced unmount on a busy