uninstall.ps1: kill llama-server too (pkill self-match made it a no-op)

The WSL cleanup ran `pkill -9 -f unsloth_studio` then `pkill -9 -f llama-server`,
but the `bash -lc <cmd>` shell's own argv contains those literal patterns, so the
first pkill SIGKILLed the shell before the llama-server pkill (and trailing `true`)
ever ran -- leaving a running llama-server (dynamic port, not covered by
`fuser -k 8888`) alive after uninstall. Use the [x]-regex self-exclusion trick
('[u]nsloth_studio' / '[l]lama-server') so the shell's argv no longer contains the
matched substring; real target processes still match. Verified in WSL: shell
survives, both dummy processes are killed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Daniel Han 2026-06-03 03:53:14 -07:00
commit 5ecadb8512

View file

@ -377,7 +377,16 @@ function Uninstall-UnslothStudio {
# ~/.local/bin/unsloth -> <venv>/bin/unsloth. rm -rf of ~/.unsloth
# above deletes its target but leaves the symlink dangling, so the
# `unsloth` command still resolves on PATH after an uninstall.
$_clean = 'rm -rf /root/.unsloth /home/*/.unsloth /root/llama-cuda /root/provision_llama_cuda.sh /root/llama_cuda_build.log 2>/dev/null; rm -f /root/.local/bin/unsloth /home/*/.local/bin/unsloth 2>/dev/null; fuser -k 8888/tcp 2>/dev/null; pkill -9 -f unsloth_studio 2>/dev/null; pkill -9 -f llama-server 2>/dev/null; true'
# The pkill patterns use the [x]-regex self-exclusion trick: this very
# `bash -lc <cmd>` shell's own argv contains the literal pattern text, so a
# plain `pkill -f unsloth_studio` would match (and SIGKILL) the shell itself
# before the next command runs -- which is why rm goes first AND why the second
# pkill (llama-server, a dynamic port not covered by `fuser -k 8888`) never
# fired. Writing the pattern as '[u]nsloth_studio' means the shell's argv holds
# "[u]nsloth_studio" (no literal "unsloth_studio" substring) so it no longer
# self-matches, while real target processes (cmdline contains "unsloth_studio")
# still match. Same for '[l]lama-server'.
$_clean = 'rm -rf /root/.unsloth /home/*/.unsloth /root/llama-cuda /root/provision_llama_cuda.sh /root/llama_cuda_build.log 2>/dev/null; rm -f /root/.local/bin/unsloth /home/*/.local/bin/unsloth 2>/dev/null; fuser -k 8888/tcp 2>/dev/null; pkill -9 -f ''[u]nsloth_studio'' 2>/dev/null; pkill -9 -f ''[l]lama-server'' 2>/dev/null; true'
$_cands = @('', 'Ubuntu', 'Ubuntu-24.04', 'Ubuntu-22.04', 'Debian')
if ($env:UNSLOTH_WSL_DISTRO) { $_cands = @($env:UNSLOTH_WSL_DISTRO) + $_cands }
$_done = @{}