#!/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/LFM2.5-...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. Match the model instead. Override MODEL if you change it. MODEL="${MODEL:-LFM2}" PAT='mavend|mavsttd|mavttsd|mavweb|mavpoll|mavenclient' LLM="llama-server.*${MODEL}" 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