# MAYA OS ENTERPRISE — OPERATIONS & TROUBLESHOOTING GUIDE

## 1. MySQL Startup Error: `DB_ENGINE must be 'mysql'`

`backend/config/settings.py` enforces MySQL at startup. Ensure `.env` sets:
```env
DB_ENGINE=mysql
MYSQL_HOST=mysql   # or 127.0.0.1 for host MySQL
MYSQL_PORT=3306
```

## 2. Bootstrap Endpoint Returns `403 Forbidden`

- **"Bootstrap endpoint is permanently locked"**: Intended security behavior once a Super Admin user exists or the Setup Wizard finalized (`InstallationSession.status == LOCKED`). Sign in via `/login` or use `./create-superadmin.sh` if creating a break-glass account via SSH.
- **"Invalid or missing BOOTSTRAP_SETUP_TOKEN"**: Copy the exact `BOOTSTRAP_SETUP_TOKEN` value from server `.env`.
- **"Default usernames ('admin', 'root', 'test', 'demo') are prohibited"**: Choose a unique corporate username (e.g. `erp_director`).

## 3. MySQL Deadlock / Lock Wait Timeout (`1205` / `1213`)

Verify MySQL isolation level is `READ-COMMITTED` (`deployment/mysql/my.cnf` and `settings.py` `init_command`). Service helpers wrapped in `mysql_deadlock_retry` (`apps/system_admin/mysql_concurrency.py`) automatically perform jittered exponential retries. Check `./health-check.sh` output for active session posture.

## 4. Backup / Restore Errors

- **"SHA-256 verification FAILED"**: Backup file was corrupted or truncated. Never bypass checksum errors; restore from the next verified snapshot.
- **"BACKUP_ENCRYPTION_PASSPHRASE is required"**: Export the matching passphrase used when creating the `.sql.gz.enc` artifact before running `./restore.sh`.
- **Neither `mysqldump` nor `mariadb-dump` found**: Install `default-mysql-client` (or run `./backup.sh --docker` to execute inside the `mysql` container).

## 5. Inspecting Logs & Service State

```bash
./health-check.sh
docker compose ps
docker compose logs --tail=100 backend asgi celery_critical mysql
```

