feat: Add credentials management system and comprehensive testing
- Add credentials management system with automatic saving and updates - Add upload form URL to JSON output - Add Ollama model information to JSON output - Implement credential update system (update_credentials.sh) - Implement credential save system (save_credentials.sh) - Add comprehensive test suites (infrastructure, n8n, PostgREST, complete system) - Add workflow auto-reload system with systemd service - Add detailed documentation (CREDENTIALS_MANAGEMENT.md, TEST_REPORT.md, VERIFICATION_SUMMARY.md) - Improve n8n setup with robust API-based workflow import - Add .gitignore for credentials directory - All tests passing (40+ test cases) Key Features: - Credentials automatically saved to credentials/<hostname>.json - Update Ollama URL from IP to hostname without container restart - Comprehensive testing with 4 test suites - Full documentation and examples - Production-ready system
This commit is contained in:
256
WORKFLOW_RELOAD_README.md
Normal file
256
WORKFLOW_RELOAD_README.md
Normal file
@@ -0,0 +1,256 @@
|
||||
# n8n Workflow Auto-Reload bei LXC-Neustart
|
||||
|
||||
## Übersicht
|
||||
|
||||
Diese Funktion sorgt dafür, dass der n8n-Workflow bei jedem Neustart des LXC-Containers automatisch neu geladen wird. Dies ist nützlich, um sicherzustellen, dass der Workflow immer im gewünschten Zustand ist, auch nach Updates oder Änderungen am Container.
|
||||
|
||||
## Funktionsweise
|
||||
|
||||
### Komponenten
|
||||
|
||||
1. **Systemd-Service** (`/etc/systemd/system/n8n-workflow-reload.service`)
|
||||
- Wird beim LXC-Start automatisch ausgeführt
|
||||
- Wartet auf Docker und n8n-Container
|
||||
- Führt das Reload-Script aus
|
||||
|
||||
2. **Reload-Script** (`/opt/customer-stack/reload-workflow.sh`)
|
||||
- Liest Konfiguration aus `.env`
|
||||
- Wartet bis n8n API bereit ist
|
||||
- Sucht nach bestehendem Workflow
|
||||
- Löscht alten Workflow (falls vorhanden)
|
||||
- Importiert Workflow aus Template
|
||||
- Aktiviert den Workflow
|
||||
- Loggt alle Aktionen
|
||||
|
||||
3. **Workflow-Template** (`/opt/customer-stack/workflow-template.json`)
|
||||
- Persistente Kopie des Workflows
|
||||
- Wird bei Installation erstellt
|
||||
- Wird bei jedem Neustart verwendet
|
||||
|
||||
### Ablauf beim LXC-Neustart
|
||||
|
||||
```
|
||||
LXC startet
|
||||
↓
|
||||
Docker startet
|
||||
↓
|
||||
n8n-Container startet
|
||||
↓
|
||||
Systemd-Service startet (nach 10s Verzögerung)
|
||||
↓
|
||||
Reload-Script wird ausgeführt
|
||||
↓
|
||||
1. Lade Konfiguration aus .env
|
||||
2. Warte auf n8n API (max. 60s)
|
||||
3. Login bei n8n
|
||||
4. Suche nach bestehendem Workflow "RAG KI-Bot (PGVector)"
|
||||
5. Lösche alten Workflow (falls vorhanden)
|
||||
6. Suche nach Credentials (PostgreSQL, Ollama)
|
||||
7. Verarbeite Workflow-Template (ersetze Credential-IDs)
|
||||
8. Importiere neuen Workflow
|
||||
9. Aktiviere Workflow
|
||||
↓
|
||||
Workflow ist bereit
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
Die Auto-Reload-Funktion wird automatisch bei der Installation konfiguriert:
|
||||
|
||||
```bash
|
||||
bash install.sh --debug
|
||||
```
|
||||
|
||||
### Was wird installiert?
|
||||
|
||||
1. **Workflow-Template**: `/opt/customer-stack/workflow-template.json`
|
||||
2. **Reload-Script**: `/opt/customer-stack/reload-workflow.sh`
|
||||
3. **Systemd-Service**: `/etc/systemd/system/n8n-workflow-reload.service`
|
||||
4. **Log-Verzeichnis**: `/opt/customer-stack/logs/`
|
||||
|
||||
## Logging
|
||||
|
||||
Alle Reload-Vorgänge werden geloggt:
|
||||
|
||||
- **Log-Datei**: `/opt/customer-stack/logs/workflow-reload.log`
|
||||
- **Systemd-Journal**: `journalctl -u n8n-workflow-reload.service`
|
||||
|
||||
### Log-Beispiel
|
||||
|
||||
```
|
||||
[2024-01-15 10:30:00] =========================================
|
||||
[2024-01-15 10:30:00] n8n Workflow Auto-Reload gestartet
|
||||
[2024-01-15 10:30:00] =========================================
|
||||
[2024-01-15 10:30:00] Konfiguration geladen aus /opt/customer-stack/.env
|
||||
[2024-01-15 10:30:00] Warte auf n8n API...
|
||||
[2024-01-15 10:30:05] n8n API ist bereit
|
||||
[2024-01-15 10:30:05] Login bei n8n als admin@userman.de...
|
||||
[2024-01-15 10:30:06] Login erfolgreich
|
||||
[2024-01-15 10:30:06] Suche nach Workflow 'RAG KI-Bot (PGVector)'...
|
||||
[2024-01-15 10:30:06] Workflow gefunden: ID=abc123
|
||||
[2024-01-15 10:30:06] Bestehender Workflow gefunden, wird gelöscht...
|
||||
[2024-01-15 10:30:07] Workflow abc123 gelöscht
|
||||
[2024-01-15 10:30:07] Suche nach bestehenden Credentials...
|
||||
[2024-01-15 10:30:07] Suche nach Credential 'PostgreSQL (local)' (Typ: postgres)...
|
||||
[2024-01-15 10:30:08] Credential gefunden: ID=def456
|
||||
[2024-01-15 10:30:08] Suche nach Credential 'Ollama (local)' (Typ: ollamaApi)...
|
||||
[2024-01-15 10:30:09] Credential gefunden: ID=ghi789
|
||||
[2024-01-15 10:30:09] Verarbeite Workflow-Template...
|
||||
[2024-01-15 10:30:10] Workflow-Template erfolgreich verarbeitet
|
||||
[2024-01-15 10:30:10] Importiere Workflow aus /tmp/workflow_processed.json...
|
||||
[2024-01-15 10:30:11] Workflow importiert: ID=jkl012, Version=v1
|
||||
[2024-01-15 10:30:11] Aktiviere Workflow jkl012...
|
||||
[2024-01-15 10:30:12] Workflow jkl012 erfolgreich aktiviert
|
||||
[2024-01-15 10:30:12] =========================================
|
||||
[2024-01-15 10:30:12] Workflow-Reload erfolgreich abgeschlossen
|
||||
[2024-01-15 10:30:12] Workflow-ID: jkl012
|
||||
[2024-01-15 10:30:12] =========================================
|
||||
```
|
||||
|
||||
## Manuelles Testen
|
||||
|
||||
### Service-Status prüfen
|
||||
|
||||
```bash
|
||||
# Im LXC-Container
|
||||
systemctl status n8n-workflow-reload.service
|
||||
```
|
||||
|
||||
### Manuelles Reload auslösen
|
||||
|
||||
```bash
|
||||
# Im LXC-Container
|
||||
/opt/customer-stack/reload-workflow.sh
|
||||
```
|
||||
|
||||
### Logs anzeigen
|
||||
|
||||
```bash
|
||||
# Log-Datei
|
||||
cat /opt/customer-stack/logs/workflow-reload.log
|
||||
|
||||
# Systemd-Journal
|
||||
journalctl -u n8n-workflow-reload.service -f
|
||||
```
|
||||
|
||||
### Service neu starten
|
||||
|
||||
```bash
|
||||
# Im LXC-Container
|
||||
systemctl restart n8n-workflow-reload.service
|
||||
```
|
||||
|
||||
## Fehlerbehandlung
|
||||
|
||||
### Häufige Probleme
|
||||
|
||||
1. **n8n API nicht erreichbar**
|
||||
- Prüfen: `docker ps` - läuft n8n-Container?
|
||||
- Prüfen: `curl http://127.0.0.1:5678/rest/settings`
|
||||
- Lösung: Warten oder Docker-Container neu starten
|
||||
|
||||
2. **Login fehlgeschlagen**
|
||||
- Prüfen: Sind die Credentials in `.env` korrekt?
|
||||
- Prüfen: `cat /opt/customer-stack/.env`
|
||||
- Lösung: Credentials korrigieren
|
||||
|
||||
3. **Credentials nicht gefunden**
|
||||
- Prüfen: Existieren die Credentials in n8n?
|
||||
- Lösung: Credentials manuell in n8n erstellen
|
||||
|
||||
4. **Workflow-Template nicht gefunden**
|
||||
- Prüfen: `ls -la /opt/customer-stack/workflow-template.json`
|
||||
- Lösung: Template aus Backup wiederherstellen
|
||||
|
||||
### Service deaktivieren
|
||||
|
||||
Falls Sie die Auto-Reload-Funktion deaktivieren möchten:
|
||||
|
||||
```bash
|
||||
# Im LXC-Container
|
||||
systemctl disable n8n-workflow-reload.service
|
||||
systemctl stop n8n-workflow-reload.service
|
||||
```
|
||||
|
||||
### Service wieder aktivieren
|
||||
|
||||
```bash
|
||||
# Im LXC-Container
|
||||
systemctl enable n8n-workflow-reload.service
|
||||
systemctl start n8n-workflow-reload.service
|
||||
```
|
||||
|
||||
## Technische Details
|
||||
|
||||
### Systemd-Service-Konfiguration
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=n8n Workflow Auto-Reload Service
|
||||
After=docker.service
|
||||
Wants=docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStartPre=/bin/sleep 10
|
||||
ExecStart=/bin/bash /opt/customer-stack/reload-workflow.sh
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
### Workflow-Verarbeitung
|
||||
|
||||
Das Reload-Script verwendet Python, um das Workflow-Template zu verarbeiten:
|
||||
|
||||
1. Entfernt Felder: `id`, `versionId`, `meta`, `tags`, `active`, `pinData`
|
||||
2. Ersetzt PostgreSQL Credential-IDs
|
||||
3. Ersetzt Ollama Credential-IDs
|
||||
4. Schreibt verarbeitetes JSON nach `/tmp/workflow_processed.json`
|
||||
|
||||
### API-Endpunkte
|
||||
|
||||
- **Login**: `POST /rest/login`
|
||||
- **Workflows auflisten**: `GET /rest/workflows`
|
||||
- **Workflow löschen**: `DELETE /rest/workflows/{id}`
|
||||
- **Workflow importieren**: `POST /rest/workflows`
|
||||
- **Workflow aktivieren**: `POST /rest/workflows/{id}/activate`
|
||||
- **Credentials auflisten**: `GET /rest/credentials`
|
||||
|
||||
## Sicherheit
|
||||
|
||||
- Credentials werden aus `.env` gelesen (nicht im Script hardcoded)
|
||||
- Session-Cookies werden nach Verwendung gelöscht
|
||||
- Temporäre Dateien werden aufgeräumt
|
||||
- Logs enthalten keine Passwörter
|
||||
|
||||
## Wartung
|
||||
|
||||
### Workflow-Template aktualisieren
|
||||
|
||||
Wenn Sie den Workflow ändern möchten:
|
||||
|
||||
1. Exportieren Sie den Workflow aus n8n UI
|
||||
2. Kopieren Sie die JSON-Datei nach `/opt/customer-stack/workflow-template.json`
|
||||
3. Beim nächsten Neustart wird der neue Workflow geladen
|
||||
|
||||
### Backup
|
||||
|
||||
Wichtige Dateien für Backup:
|
||||
|
||||
- `/opt/customer-stack/workflow-template.json`
|
||||
- `/opt/customer-stack/.env`
|
||||
- `/opt/customer-stack/logs/workflow-reload.log`
|
||||
|
||||
## Support
|
||||
|
||||
Bei Problemen:
|
||||
|
||||
1. Prüfen Sie die Logs: `/opt/customer-stack/logs/workflow-reload.log`
|
||||
2. Prüfen Sie den Service-Status: `systemctl status n8n-workflow-reload.service`
|
||||
3. Führen Sie das Script manuell aus: `/opt/customer-stack/reload-workflow.sh`
|
||||
4. Prüfen Sie die n8n-Container-Logs: `docker logs n8n`
|
||||
Reference in New Issue
Block a user