# Hermes Dashboard — systemd Service Setup

Full reference for running `hermes dashboard` as a persistent user service.

## Service Unit (Localhost only)

`~/.config/systemd/user/hermes-dashboard.service`:

```ini
[Unit]
Description=Hermes Agent Web Dashboard
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/home/user/.hermes/hermes-agent/venv/bin/hermes dashboard --host 127.0.0.1 --port 9119 --no-open
Restart=on-failure
RestartSec=5
Environment=HERMES_HOME=/home/user/.hermes

[Install]
WantedBy=default.target
```

## Service Unit (Tailscale / LAN access)

For access from Tailscale or LAN devices. Safe because Tailscale/WireGuard gates network access, or use nftables to restrict source IPs.

```ini
[Unit]
Description=Hermes Agent Web Dashboard
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/home/user/.hermes/hermes-agent/venv/bin/hermes dashboard --host 0.0.0.0 --port 9119 --no-open --insecure
Restart=on-failure
RestartSec=5
Environment=HERMES_HOME=/home/user/.hermes

[Install]
WantedBy=default.target
```

## Lifecycle

```bash
# Install & start
systemctl --user daemon-reload
systemctl --user enable --now hermes-dashboard.service

# Status
systemctl --user status hermes-dashboard.service

# Logs
journalctl --user -u hermes-dashboard.service -f

# Restart
systemctl --user restart hermes-dashboard.service

# Stop (use systemctl to avoid catch-22)
systemctl --user stop hermes-dashboard.service

# Disable auto-start
systemctl --user disable hermes-dashboard.service
```

**Pitfall:** `hermes dashboard --stop` kills ALL dashboard processes, including the one being managed by systemd. Since the service has `Restart=on-failure`, systemd immediately restarts it — creating a perpetual restart loop. **Always use `systemctl --user stop`** to stop a systemd-managed dashboard, never `hermes dashboard --stop`. If you accidentally trigger the loop, run `systemctl --user stop hermes-dashboard.service` to break it.

## Prerequisites

1. `hermes-agent[web]` extra installed:
   ```bash
   cd ~/.hermes/hermes-agent
   uv pip install -e ".[web]"
   ```

2. `~/.local/bin/hermes` shebang points to venv Python, not system Python:
   ```bash
   head -1 ~/.local/bin/hermes
   sed -i '1s|^#!/usr/bin/python3|#!/home/user/.hermes/hermes-agent/venv/bin/python3|' ~/.local/bin/hermes
   ```

3. Systemd user linger enabled (stays alive after SSH logout):
   ```bash
   sudo loginctl enable-linger $USER
   ```

## Verification

```bash
curl -s http://127.0.0.1:9119/ | head -5
# Should return: <!doctype html><html lang="en">...
```
