# Mattermost Runbook

**Status:** DEPRECATED 2026-05-18 — mm.basicconsulting.no decommissioned per CEO answer #5. Replace with comment `# DEPRECATED 2026-05-18` or delete if easy.

# Runbook: Mattermost

**Service Type:** Team Communication Platform
**Container:** mattermost (mattermost/mattermost-team-edition:latest)
**Ports:** 8065 (internal + external)
**External URL:** https://mm.basicconsulting.no
**Database:** PostgreSQL 15 (mattermost-db)
**Compose File:** ~/system/services/mattermost/docker-compose.yml

---

## Service Info

Mattermost is the primary team communication platform for BasicAS Group. Runs via Docker Compose with PostgreSQL backend.

**Stack:**
- **mattermost** - Main app (Team Edition)
- **mattermost-db** - PostgreSQL 15 (alpine)

**External Access:**
- Exposed via Cloudflare Tunnel: mm.basicconsulting.no
- Configured for Norwegian locale (nb) + English fallback
- SMTP via one.com (info@basicconsulting.no)

**Admin Access:**
- Web UI: http://localhost:8065 (local) or https://mm.basicconsulting.no
- Database: postgres://mmuser:BasicMM2026!@localhost:5432/mattermost (internal only)

---

## Status Check

### Container Health
```bash
docker ps | grep mattermost
```

Expected output:
```
mattermost      Up X hours (healthy)
mattermost-db   Up X hours
```

### HTTP Check
```bash
curl -I http://localhost:8065
```

Expected: `200 OK`

### External Access Check
```bash
curl -I https://mm.basicconsulting.no
```

Expected: `200 OK`

### Database Check
```bash
docker exec mattermost-db psql -U mmuser -d mattermost -c "SELECT count(*) FROM users;"
```

---

## Restart Procedure

### Quick Restart (Container Only)
```bash
docker restart mattermost
```

### Full Stack Restart (Container + Database)
```bash
cd ~/system/services/mattermost
docker compose down
docker compose up -d
```

Wait 30-60 seconds for healthcheck to pass, then verify:
```bash
docker ps | grep mattermost
curl -I http://localhost:8065
```

---

## Troubleshooting

### Problem: Container won't start
**Check logs:**
```bash
docker logs mattermost --tail 100
```

**Common causes:**
1. Database not ready - wait 30s and retry
2. Port 8065 already bound - check `lsof -i :8065`
3. Volume permission issues - check `~/system/services/mattermost/data/`

**Fix:**
```bash
cd ~/system/services/mattermost
docker compose down
docker compose up -d mattermost-db
sleep 30
docker compose up -d mattermost
```

### Problem: Login issues (can't sign in)
**Check SMTP:**
```bash
docker exec mattermost cat /mattermost/config/config.json | grep -A5 EmailSettings
```

**Reset admin password:**
```bash
docker exec -it mattermost mattermost user reset_password <user-email>
```

### Problem: WebSocket errors (messages not real-time)
**Check site URL:**
```bash
docker exec mattermost env | grep MM_SERVICESETTINGS_SITEURL
```

Expected: `MM_SERVICESETTINGS_SITEURL=https://mm.basicconsulting.no`

**If wrong, update in docker-compose.yml and restart.**

### Problem: Database connection issues
**Check database health:**
```bash
docker exec mattermost-db pg_isready -U mmuser
```

**Check connection string:**
```bash
docker exec mattermost env | grep MM_SQLSETTINGS_DATASOURCE
```

Expected: `postgres://mmuser:BasicMM2026!@mattermost-db:5432/mattermost?sslmode=disable&connect_timeout=10`

---

## Dependencies

- **Docker** - Service runtime
- **Cloudflare Tunnel** - External access (mm.basicconsulting.no)
- **one.com SMTP** - Email notifications (send.one.com:465)

**No dependencies on other local services.**

---

## Backup

### Database Dump
```bash
docker exec mattermost-db pg_dump -U mmuser mattermost | gzip > ~/backups/mattermost-$(date +%Y%m%d-%H%M%S).sql.gz
```

### Data Volumes
```bash
cd ~/system/services/mattermost
tar -czf ~/backups/mattermost-data-$(date +%Y%m%d-%H%M%S).tar.gz data/ config/ logs/ plugins/
```

### Restore from Backup
```bash
# Stop service
cd ~/system/services/mattermost
docker compose down

# Restore database
gunzip -c ~/backups/mattermost-YYYYMMDD-HHMMSS.sql.gz | docker exec -i mattermost-db psql -U mmuser -d mattermost

# Restore data (if needed)
cd ~/system/services/mattermost
tar -xzf ~/backups/mattermost-data-YYYYMMDD-HHMMSS.tar.gz

# Start service
docker compose up -d
```

---

## Configuration

### Key Environment Variables
- `MM_SERVICESETTINGS_SITEURL` - External URL
- `MM_SQLSETTINGS_DATASOURCE` - Database connection string
- `MM_EMAILSETTINGS_SMTPSERVER` - SMTP host (send.one.com)
- `MM_EMAILSETTINGS_SMTPPORT` - SMTP port (465)
- `MM_EMAILSETTINGS_SMTPUSERNAME` - SMTP user (info@basicconsulting.no)
- `MM_LOCALIZATIONSETTINGS_DEFAULTSERVERLLOCALE` - Server locale (nb)

Full config: ~/system/services/mattermost/docker-compose.yml

### Admin UI Config
Access: System Console (requires System Admin role)

---

## Notes

- **Security:** Passwords stored in docker-compose.yml (plaintext) - task #310 to move to secrets
- **MFA:** Not yet enabled - task #309 to enable multi-factor auth
- **Max file size:** 100MB (104857600 bytes)
- **Max users per team:** 50
- **Open signup:** Disabled (invite-only)
- **Email verification:** Disabled (faster onboarding)

---

**Last updated:** 2026-02-10
**Maintained by:** John (AI Director)