#!/usr/bin/env bash set -euo pipefail find_lab_root(){ if [[ -n "${AZEROTHAI_PLAYABLE_ROOT:-}" && -d "$AZEROTHAI_PLAYABLE_ROOT" ]]; then printf '%s' "$AZEROTHAI_PLAYABLE_ROOT"; return fi for root in "$HOME/azerothai-pc-lab" "$HOME/azerothai-playable"; do if [[ -d "$root" ]]; then printf '%s' "$root"; return; fi done printf '%s' "$HOME/azerothai-playable" } LAB_ROOT="$(find_lab_root)" ACORE_ROOT="$LAB_ROOT/azerothcore" stop_pid_file(){ local label="$1" file="$2" if [[ ! -f "$file" ]]; then return; fi local pid pid="$(cat "$file" 2>/dev/null || true)" if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then echo "Stopping $label PID $pid..." kill "$pid" 2>/dev/null || true for _ in {1..20}; do if ! kill -0 "$pid" 2>/dev/null; then break; fi sleep 0.25 done kill -9 "$pid" 2>/dev/null || true fi rm -f "$file" } if sudo systemctl list-unit-files azerothai-autonomy.service >/dev/null 2>&1; then echo "Stopping AzerothAI autonomy service..." sudo systemctl disable --now azerothai-autonomy.service >/dev/null 2>&1 || true fi if sudo systemctl list-unit-files azerothai-ale-relay.service >/dev/null 2>&1; then echo "Stopping AzerothAI ALE relay service..." sudo systemctl disable --now azerothai-ale-relay.service >/dev/null 2>&1 || true fi stop_pid_file "AzerothAI autonomy worker" "$LAB_ROOT/autonomy.pid" if [[ -d "$ACORE_ROOT" ]]; then echo "Stopping AzerothCore containers..." (cd "$ACORE_ROOT" && docker compose down) fi stop_pid_file "AzerothAI" "$LAB_ROOT/azerothai.pid" echo "Stopped. Database, client data, AzerothAI state, bot identities, memories, and logs were preserved."