#!/usr/bin/env bash # Unified script to stop all Maven services. # Usage: ./kill-maven.sh # - Graceful SIGTERM is attempted first. # - If any process lingers, force with SIGKILL. set -euo pipefail # The llama-server the phraser spawns has NO "maven" in its command line (its # args are `-m /path/to/.gguf --port ...`), so a `llama-server.*maven` # pattern matches nothing and leaks it — the exact bug that let orphans pile up # and OOM the box. # # We used to match the model name, defaulting to LFM2. The deploy now runs # Qwen3.5-0.8B, so that default matched nothing and the server survived every # kill. Match any llama-server serving a .gguf instead, so swapping the model in # deploy/mavend.json cannot break this script again. Set MODEL to narrow it if # some other llama-server on this box must be left alone. MODEL="${MODEL:-}" PAT='mavend|mavsttd|mavttsd|mavweb|mavpoll|mavenclient' if [ -n "$MODEL" ]; then LLM="llama-server.*${MODEL}" else LLM='llama-server.*\.gguf' fi echo "--- Sending graceful SIGTERM to Maven services ---" pkill -TERM -f "$PAT" || true # mavend's Pdeathsig SIGKILLs its llama-server on exit, but sweep strays too # (an orphan whose mavend already died has no one left to reap it). pkill -TERM -f "$LLM" || true echo "--- Verifying processes are gone ---" sleep 1 PIDS=$(pgrep -d ',' -f "$PAT|$LLM") || PIDS="" if [ -n "$PIDS" ]; then echo "Warning: some processes still alive. PIDs: $PIDS" echo "--- Force killing with SIGKILL ---" echo "$PIDS" | tr ',' '\n' | xargs -r kill -9 echo "Done (SIGKILL)." else echo "All services gracefully stopped." fi