# Arbiter 3.0 Deployment Guide

**Location:** Command Center (63.143.34.217)  
**Service:** `arbiter-3` (systemd)  
**Directory:** `/opt/arbiter-3.0`  
**Dashboard:** https://discord-bot.firefrostgaming.com/admin

---

## 🚀 One-Click Deploy (Trinity Console)

**For Holly, Meg, and Michael:**

1. Push your code changes to `firefrost-services` repo
2. Open Trinity Console: https://discord-bot.firefrostgaming.com/admin
3. Click the **"🚀 Deploy Arbiter"** button in the sidebar
4. Wait for success confirmation

That's it! The button pulls latest code from Gitea and restarts the service.

---

## ⚠️ IMPORTANT: Arbiter is NOT a Git Repo

`/opt/arbiter-3.0` on Command Center is **not** a git repository. It's a deployment target.

**Source of truth:** `firefrost-services` repo → `services/arbiter-3.0/`

**Why?** Production servers shouldn't have git credentials or .git history. Deploy by copying files.

---

## Manual Deploy (SSH Required)

**On Command Center:**
```bash
bash /opt/arbiter-3.0/deploy.sh
```

**Or remote curl:**
```bash
curl -fsSL https://git.firefrostgaming.com/firefrost-gaming/firefrost-services/raw/branch/main/services/arbiter-3.0/deploy.sh | bash
```

---

## First-Time Server Setup

If setting up deploy button for the first time, Michael needs to run these on Command Center:

**1. Copy deploy script to /opt/scripts:**
```bash
sudo mkdir -p /opt/scripts
sudo cp /opt/arbiter-3.0/deploy.sh /opt/scripts/deploy-arbiter.sh
sudo chmod +x /opt/scripts/deploy-arbiter.sh
```

**2. Configure sudoers (allow Arbiter to run deploy script):**
```bash
sudo visudo
```
Add this line:
```
architect ALL=(ALL) NOPASSWD: /opt/scripts/deploy-arbiter.sh
```

**3. Create log file:**
```bash
sudo touch /var/log/trinity-deployments.log
sudo chown architect:architect /var/log/trinity-deployments.log
```

---

## Verify Deployment

```bash
# Check service status
systemctl status arbiter-3

# Check logs
journalctl -u arbiter-3 -n 50

# Check deployment log
tail -20 /var/log/trinity-deployments.log

# Test dashboard
curl -s https://discord-bot.firefrostgaming.com/admin | head -5
```

---

## Common Issues

### "Deployment already in progress"
**Cause:** Previous deploy didn't finish or crashed  
**Fix:** `rm -rf /tmp/arbiter_deploy.lock` then try again

### "fatal: not a git repository"
**Cause:** Someone tried to `git pull` in `/opt/arbiter-3.0`  
**Fix:** Use the deploy script or manual copy method above

### "/tmp/firefrost-services already exists"
**Cause:** Previous deploy didn't clean up  
**Fix:** `rm -rf /tmp/firefrost-services /tmp/firefrost-services-deploy-*` then try again

### Service fails to start
**Check:** `journalctl -u arbiter-3 -n 50`  
**Common causes:**
- Missing .env file
- Database connection failed
- Port already in use
- Syntax error in code

---

## Environment Variables

Required in `/opt/arbiter-3.0/.env`:
```
DATABASE_URL=postgresql://...
DISCORD_TOKEN=...
DISCORD_CLIENT_ID=...
DISCORD_CLIENT_SECRET=...
PANEL_URL=https://panel.firefrostgaming.com
PANEL_APPLICATION_KEY=...
PANEL_CLIENT_KEY=...
STRIPE_SECRET_KEY=...
STRIPE_WEBHOOK_SECRET=...
SESSION_SECRET=...
MINECRAFT_NEST_IDS=1,5
```

---

## For Chroniclers & Catalysts

**You cannot SSH to Command Center** (port 22 blocked from Claude sandbox).

**Workflow:**
1. Make changes to `firefrost-services/services/arbiter-3.0/`
2. Commit and push to Gitea
3. Tell your human to click "🚀 Deploy Arbiter" in Trinity Console
4. Verify via dashboard or ask them to check logs

---

**Fire + Frost + Foundation = Where Love Builds Legacy** 🔥❄️
