All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 4s
- Updated the .env loading process to first check for an explicit path, improving reliability in different working directories. - Added logging for successful .env loading and fallback mechanisms. - Enhanced EdgeDTO creation with robust error handling, including fallbacks for unsupported provenance values and logging of errors for better traceability.
106 lines
2.8 KiB
Markdown
106 lines
2.8 KiB
Markdown
# Debug: .env-Lade-Problem in Prod
|
|
|
|
**Datum**: 2026-01-12
|
|
**Version**: v4.5.10
|
|
**Status**: 🔴 Kritisch
|
|
|
|
## Problem
|
|
|
|
Möglicherweise wird die `.env`-Datei in Prod nicht korrekt geladen, was zu:
|
|
- Falschen Log-Levels (DEBUG=true wird ignoriert)
|
|
- Falschen Collection-Präfixen
|
|
- Falschen Konfigurationen
|
|
führen kann.
|
|
|
|
## Diagnose
|
|
|
|
### Schritt 1: Prüfe, ob .env-Datei existiert
|
|
|
|
```bash
|
|
# In Prod
|
|
cd ~/mindnet
|
|
ls -la .env
|
|
cat .env | head -20
|
|
```
|
|
|
|
### Schritt 2: Prüfe Arbeitsverzeichnis beim Start
|
|
|
|
```bash
|
|
# In Prod - prüfe, von wo uvicorn gestartet wird
|
|
ps aux | grep uvicorn
|
|
# Oder in systemd service:
|
|
cat /etc/systemd/system/mindnet.service | grep WorkingDirectory
|
|
```
|
|
|
|
### Schritt 3: Verifikations-Script ausführen
|
|
|
|
```bash
|
|
# In Prod
|
|
cd ~/mindnet
|
|
source .venv/bin/activate
|
|
python3 scripts/verify_env_loading.py
|
|
```
|
|
|
|
**Erwartete Ausgabe**:
|
|
```
|
|
✅ .env geladen von: /path/to/mindnet/.env
|
|
✅ COLLECTION_PREFIX = mindnet
|
|
✅ DEBUG = true
|
|
```
|
|
|
|
### Schritt 4: Manuelle Verifikation
|
|
|
|
```python
|
|
# In Python-REPL in Prod
|
|
import os
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
# Prüfe aktuelles Verzeichnis
|
|
print(f"CWD: {Path.cwd()}")
|
|
print(f"Projekt-Root: {Path(__file__).parent.parent.parent}")
|
|
|
|
# Lade .env
|
|
env_file = Path(".env")
|
|
if env_file.exists():
|
|
load_dotenv(env_file, override=True)
|
|
print(f"✅ .env geladen: {env_file.absolute()}")
|
|
else:
|
|
print(f"❌ .env nicht gefunden in: {env_file.absolute()}")
|
|
|
|
# Prüfe kritische Variablen
|
|
print(f"DEBUG: {os.getenv('DEBUG', 'NICHT GESETZT')}")
|
|
print(f"COLLECTION_PREFIX: {os.getenv('COLLECTION_PREFIX', 'NICHT GESETZT')}")
|
|
```
|
|
|
|
## Mögliche Ursachen
|
|
|
|
### 1. Arbeitsverzeichnis-Problem
|
|
- **Problem**: uvicorn wird aus einem anderen Verzeichnis gestartet
|
|
- **Lösung**: Expliziter Pfad in `config.py` (bereits implementiert)
|
|
|
|
### 2. .env-Datei nicht im Projekt-Root
|
|
- **Problem**: .env liegt in `config/prod.env` statt `.env`
|
|
- **Lösung**: Symlink erstellen oder Pfad anpassen
|
|
|
|
### 3. Systemd-Service ohne WorkingDirectory
|
|
- **Problem**: Service startet ohne korrektes Arbeitsverzeichnis
|
|
- **Lösung**: `WorkingDirectory=/path/to/mindnet` in systemd service
|
|
|
|
### 4. Mehrere .env-Dateien
|
|
- **Problem**: Es gibt `.env`, `prod.env`, `config/prod.env` - welche wird geladen?
|
|
- **Lösung**: Expliziter Pfad oder Umgebungsvariable `DOTENV_PATH`
|
|
|
|
## Fix-Implementierung
|
|
|
|
Der Code in `app/config.py` wurde erweitert:
|
|
- ✅ Expliziter Pfad für `.env` im Projekt-Root
|
|
- ✅ Fallback auf automatische Suche
|
|
- ✅ Debug-Logging (wenn verfügbar)
|
|
|
|
## Verifikation nach Fix
|
|
|
|
1. **Log prüfen**: Sollte `✅ .env geladen von: ...` zeigen
|
|
2. **Umgebungsvariablen prüfen**: `echo $DEBUG`, `echo $COLLECTION_PREFIX`
|
|
3. **Settings prüfen**: `python3 -c "from app.config import get_settings; s = get_settings(); print(f'DEBUG: {s.DEBUG}, PREFIX: {s.COLLECTION_PREFIX}')"`
|