feat(node2): Add scripts and docs for NODE2 guardian setup

- Add start-node2-guardian.sh script for easy launch
- Add setup-node2-agents.sh to update node_id for NODE2 agents
- Add NODE2_GUARDIAN_QUICKSTART.md with detailed instructions
- Update agents node_id to node-2-macbook-m4max
This commit is contained in:
Apple
2025-12-02 06:59:48 -08:00
parent 92d8efa5b3
commit 80123fd1be
3 changed files with 257 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
# Швидкий старт Node Guardian для НОДА2 (MacBook)
## Крок 1: Перевірка доступності сервісів
```bash
# Перевірити чи Router доступний
curl http://localhost:9102/health
# Перевірити чи Swapper доступний
curl http://localhost:8890/health
```
Якщо обидва повертають `{"status":"healthy"}`, продовжуйте.
## Крок 2: Встановлення залежностей
```bash
cd /Users/apple/github-projects/microdao-daarion
pip3 install httpx
```
## Крок 3: Запуск Node Guardian
### Варіант А: Одноразовий запуск (для тестування)
```bash
cd /Users/apple/github-projects/microdao-daarion
./scripts/start-node2-guardian.sh
```
### Варіант Б: Запуск у фоновому режимі (рекомендовано)
```bash
cd /Users/apple/github-projects/microdao-daarion
# Запустити в фоні
nohup ./scripts/start-node2-guardian.sh > /tmp/node-guardian.log 2>&1 &
# Перевірити логи
tail -f /tmp/node-guardian.log
```
### Варіант В: Запуск через launchd (macOS)
Створіть файл `~/Library/LaunchAgents/com.daarion.node-guardian.plist`:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.daarion.node-guardian</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>/Users/apple/github-projects/microdao-daarion/scripts/node-guardian-loop.py</string>
<string>--node-id</string>
<string>node-2-macbook-m4max</string>
<string>--node-name</string>
<string>НОДА2</string>
<string>--city-url</string>
<string>https://daarion.space/api/city</string>
<string>--environment</string>
<string>development</string>
<string>--roles</string>
<string>gpu,ai_runtime</string>
<string>--hostname</string>
<string>$(hostname)</string>
<string>--interval</string>
<string>60</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>NODE_SWAPPER_URL</key>
<string>http://localhost:8890</string>
<key>NODE_ROUTER_URL</key>
<string>http://localhost:9102</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/node-guardian.log</string>
<key>StandardErrorPath</key>
<string>/tmp/node-guardian-error.log</string>
</dict>
</plist>
```
Завантажити:
```bash
launchctl load ~/Library/LaunchAgents/com.daarion.node-guardian.plist
launchctl start com.daarion.node-guardian
```
Перевірити статус:
```bash
launchctl list | grep node-guardian
```
## Крок 4: Перевірка роботи
### Перевірити логи:
```bash
# Якщо запущено через nohup
tail -f /tmp/node-guardian.log
# Якщо через launchd
tail -f /tmp/node-guardian.log /tmp/node-guardian-error.log
```
### Перевірити в БД (на сервері):
```bash
ssh root@144.76.224.179 "docker exec daarion-postgres psql -U postgres -d daarion -c \"SELECT node_id, swapper_healthy, swapper_models_total, router_healthy, last_heartbeat FROM node_cache WHERE node_id = 'node-2-macbook-m4max';\""
```
### Перевірити в UI:
Відкрийте `https://daarion.space/nodes/node/node-2-macbook-m4max` та перевірте:
- Swapper Service показує моделі ✅
- DAGI Router показує статус "Up" ✅
- Агенти відображаються в списку ✅
## Troubleshooting
### Guardian не запускається
1. Перевірте чи Python 3 встановлений:
```bash
python3 --version
```
2. Перевірте чи httpx встановлений:
```bash
python3 -c "import httpx; print('OK')"
```
3. Перевірте чи сервіси доступні:
```bash
curl http://localhost:9102/health
curl http://localhost:8890/health
```
### Guardian не оновлює метрики
1. Перевірте з'єднання з city-service:
```bash
curl -v https://daarion.space/api/city/health
```
2. Перевірте логи на помилки:
```bash
tail -50 /tmp/node-guardian.log | grep -i error
```
3. Перевірте чи node_id правильний:
```bash
# В логах має бути: Node ID: node-2-macbook-m4max
```
### Агенти не відображаються
1. Перевірте чи агенти мають правильний node_id:
```bash
ssh root@144.76.224.179 "docker exec daarion-postgres psql -U postgres -d daarion -c \"SELECT id, display_name, node_id FROM agents WHERE node_id = 'node-2-macbook-m4max';\""
```
2. Якщо потрібно оновити node_id для агентів:
```bash
./scripts/setup-node2-agents.sh
```

29
scripts/setup-node2-agents.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash
# Setup agents for NODE2 - update node_id for agents that should be on NODE2
set -e
echo "🔧 Setting up agents for NODE2..."
# List of agent IDs that should be on NODE2
# You can modify this list based on your needs
NODE2_AGENTS=(
"ag_atlas"
"ag_builder"
"ag_greeter"
"ag_oracle"
)
NODE_ID="node-2-macbook-m4max"
# Update node_id for each agent
for agent_id in "${NODE2_AGENTS[@]}"; do
echo " Updating $agent_id to node_id=$NODE_ID..."
ssh root@144.76.224.179 "docker exec daarion-postgres psql -U postgres -d daarion -c \"UPDATE agents SET node_id = '$NODE_ID' WHERE id = '$agent_id' AND (node_id IS NULL OR node_id = '');\""
done
echo "✅ Agents updated for NODE2"
echo ""
echo "Verifying..."
ssh root@144.76.224.179 "docker exec daarion-postgres psql -U postgres -d daarion -c \"SELECT id, display_name, node_id, status FROM agents WHERE node_id = '$NODE_ID' ORDER BY display_name;\""

50
scripts/start-node2-guardian.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Start Node Guardian for NODE2 (MacBook)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
# Check if Python 3 is available
if ! command -v python3 &> /dev/null; then
echo "❌ Python 3 is not installed"
exit 1
fi
# Check if httpx is installed
if ! python3 -c "import httpx" 2>/dev/null; then
echo "⚠️ httpx not installed. Installing..."
pip3 install httpx
fi
# Set environment variables
export NODE_ID="node-2-macbook-m4max"
export NODE_NAME="НОДА2"
export NODE_ENVIRONMENT="development"
export NODE_ROLES="gpu,ai_runtime"
export NODE_HOSTNAME="$(hostname)"
export CITY_SERVICE_URL="https://daarion.space/api/city"
export NODE_SWAPPER_URL="http://localhost:8890"
export NODE_ROUTER_URL="http://localhost:9102"
export GUARDIAN_INTERVAL="60"
echo "🚀 Starting Node Guardian for NODE2..."
echo " Node ID: $NODE_ID"
echo " City Service: $CITY_SERVICE_URL"
echo " Swapper URL: $NODE_SWAPPER_URL"
echo " Router URL: $NODE_ROUTER_URL"
echo ""
# Run node-guardian-loop
python3 "$PROJECT_ROOT/scripts/node-guardian-loop.py" \
--node-id "$NODE_ID" \
--node-name "$NODE_NAME" \
--city-url "$CITY_SERVICE_URL" \
--environment "$NODE_ENVIRONMENT" \
--roles "$NODE_ROLES" \
--hostname "$NODE_HOSTNAME" \
--interval "$GUARDIAN_INTERVAL"