# Systemd Setup for Telegram Bots

## Dev Bot (User Service)

Dev bot runs as a **user service** — no sudo required for restart.

### Commands

```bash
systemctl --user start videobot-dev
systemctl --user stop videobot-dev
systemctl --user restart videobot-dev
systemctl --user status videobot-dev
journalctl --user -u videobot-dev -f   # follow logs
```

### Initial Setup (one-time)

```bash
# Create user systemd directory
mkdir -p ~/.config/systemd/user

# Copy service file
cp ~/dev/systemd/videobot-dev.service ~/.config/systemd/user/

# Reload and enable
systemctl --user daemon-reload
systemctl --user enable videobot-dev

# Enable lingering (needs sudo, ask devops)
sudo loginctl enable-linger videobot
```

### Files

| File | Purpose |
|------|---------|
| `~/.config/systemd/user/videobot-dev.service` | Active service file |
| `~/dev/systemd/videobot-dev.service` | Source in repo |
| `~/dev/.env` | Environment variables |
| `~/dev/logs/bot.log` | Log output |

---

## Prod Bot (System Service)

Prod bot runs as a **system service** — requires sudo.

### Commands

```bash
sudo systemctl start videobot-prod
sudo systemctl stop videobot-prod
sudo systemctl restart videobot-prod
sudo systemctl status videobot-prod
sudo journalctl -u videobot-prod -f
```

### Files

| File | Purpose |
|------|---------|
| `/etc/systemd/system/videobot-prod.service` | Active service file |
| `~/dev/systemd/videobot-prod.service` | Source in repo |
| `~/prod/.env` | Environment variables |
| `~/prod/logs/bot.log` | Log output |

---

## Environment Variables

Both bots use `.env` files:

```bash
# Telegram bot token
TELEGRAM_BOT_TOKEN=...

# LaoZhang.ai API key
LAOZHANG_KEY=...

# Storage path (NFS mount)
NFS_BASE=/mnt/video

# SOCKS5 proxy (set to "none" for direct connection)
PROXY_HOST=none
PROXY_PORT=1080

# Allowed Telegram user IDs
ALLOWED_USERS=123456,789012
```

### Proxy Configuration

- `PROXY_HOST=PROXY_HOST` — use SOCKS5 proxy
- `PROXY_HOST=none` — direct connection (no proxy)

Direct connection is preferred when API is accessible without proxy.
