Files
AzerothAI/deploy/playable/install-autonomy-service.sh
T
Richard Clark 5f0fc86cf9
Core tests / core (push) Successful in 9m57s
Full verification / application (push) Failing after 5m16s
Full verification / local-brain (push) Failing after 6m15s
Realm simulation / simulated-live-world (push) Failing after 5m32s
WoW integration lab / real-worldserver (push) Canceled after 17m23s
Import verified AzerothAI snapshot from GitHub
Source branch: feature/ai-brain-router
Source commit: c2a09e0460465201a58aaab56c71424e9a96405e
2026-09-22 13:12:54 -04:00

86 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
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-pc-lab"
}
LAB_ROOT="$(find_lab_root)"
RUNTIME_ENV="$LAB_ROOT/runtime.env"
NODE_BIN="$(command -v node)"
RUN_USER="$(id -un)"
RUN_GROUP="$(id -gn)"
SERVICE_NAME="azerothai-autonomy.service"
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME"
if [[ ! -f "$RUNTIME_ENV" ]]; then
echo "Missing $RUNTIME_ENV" >&2
exit 2
fi
if ! grep -q '^AUTONOMY_TOKEN=' "$RUNTIME_ENV"; then
echo "AUTONOMY_TOKEN is missing from $RUNTIME_ENV" >&2
exit 3
fi
mkdir -p "$LAB_ROOT"
touch "$LAB_ROOT/autonomy.log"
chown "$RUN_USER:$RUN_GROUP" "$LAB_ROOT/autonomy.log"
# Stop any legacy nohup worker before handing ownership to systemd.
if [[ -f "$LAB_ROOT/autonomy.pid" ]]; then
OLD_PID="$(cat "$LAB_ROOT/autonomy.pid" 2>/dev/null || true)"
if [[ -n "$OLD_PID" ]] && kill -0 "$OLD_PID" 2>/dev/null; then
kill "$OLD_PID" 2>/dev/null || true
fi
fi
pkill -f "$REPO_ROOT/scripts/autonomy-worker.mjs" 2>/dev/null || true
echo "==> Installing persistent AzerothAI autonomy service"
sudo tee "$SERVICE_FILE" >/dev/null <<EOF
[Unit]
Description=AzerothAI autonomous high-level Playerbot brain
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=$RUN_USER
Group=$RUN_GROUP
WorkingDirectory=$REPO_ROOT
EnvironmentFile=$RUNTIME_ENV
Environment=AZEROTHAI_URL=http://127.0.0.1:8787
Environment=AUTONOMY_POLL_MS=30000
ExecStart=$NODE_BIN $REPO_ROOT/scripts/autonomy-worker.mjs
Restart=always
RestartSec=5
StandardOutput=append:$LAB_ROOT/autonomy.log
StandardError=append:$LAB_ROOT/autonomy.log
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME" >/dev/null
sudo systemctl restart "$SERVICE_NAME"
sleep 1
PID="$(sudo systemctl show -p MainPID --value "$SERVICE_NAME")"
echo "$PID" > "$LAB_ROOT/autonomy.pid"
if ! sudo systemctl is-active --quiet "$SERVICE_NAME"; then
echo "Autonomy service failed to start." >&2
sudo systemctl status "$SERVICE_NAME" --no-pager -l >&2 || true
exit 4
fi
echo "Autonomy service: active (PID $PID)"
echo "It will restart automatically after crashes and VM reboots."