From 0038b15c5b59a5b09e8c51da7df17e819a700678 Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Fri, 23 May 2025 08:22:28 +0200 Subject: [PATCH] =?UTF-8?q?Update:=20Dokumentation=20und=20Production=20Se?= =?UTF-8?q?tup=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 596 ++++++++++++++++++++++++++++-------- backend/PRODUCTION_SETUP.md | 328 +++++++++++++++++++- 2 files changed, 793 insertions(+), 131 deletions(-) diff --git a/README.md b/README.md index 57d5f5cb..685031b2 100755 --- a/README.md +++ b/README.md @@ -1,139 +1,475 @@ -# 📩 MYP - Manage your Printer +# đŸ–šïž MYP - Manage your Printer -MYP *(Manage your Printer)* ist eine Plattform zur Reservierung von 3D-Druckern, die fĂŒr die TBA im Werk 040, Berlin-Marienfelde, entwickelt wurde. +[![Docker](https://img.shields.io/badge/Docker-Ready-blue?logo=docker)](https://docker.com) +[![Linux](https://img.shields.io/badge/Linux-Compatible-green?logo=linux)](https://linux.org) +[![Windows](https://img.shields.io/badge/Windows-Compatible-blue?logo=windows)](https://windows.com) +[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md) +[![Version](https://img.shields.io/badge/Version-2.0.0-brightgreen.svg)](https://github.com) -> Frontend: https://git.i.mercedes-benz.com/TBA-Berlin-FI/MYP/tree/main/frontend +MYP *(Manage your Printer)* ist eine moderne, containerbasierte Plattform zur Verwaltung und Reservierung von 3D-Druckern, entwickelt fĂŒr die TBA im Werk 040, Berlin-Marienfelde. -> ⚠ MYP ist zzt. in Entwicklung +## đŸ—ïž Architektur -> ‌ Datenbank aus Blueprint steht im Konflikt zu MYP.sql - Integration muss besprochen werden +Das System basiert auf einer **Microservice-Architektur** mit klarer Trennung zwischen Frontend und Backend: -> 💡 Vorschlag wenn machbar @Torben: Aufteilung der Datenbanken? API ist ja nur fĂŒr Drucker zustĂ€ndig; WebInterface fĂŒr Authentifizierung, Sessions etc. +- **đŸ–„ïž Backend**: Flask API Server (Python) - Port 5000 +- **🌐 Frontend**: Next.js Web Interface (TypeScript/React) - Port 3000 +- **🔄 Proxy**: Caddy Reverse Proxy - Port 80/443 +- **📊 Monitoring**: Prometheus & Grafana (Entwicklung) -> UltiMaker HTTP API: https://support.makerbot.com/s/article/1667412427787 +### 🔧 Technologie-Stack + +**Backend:** +- Flask 3.0+ (Python Web Framework) +- SQLAlchemy (ORM) +- JWT Authentication +- TAPO Smart Plug Integration +- RESTful API Design + +**Frontend:** +- Next.js 14+ (React Framework) +- TypeScript (Type Safety) +- Tailwind CSS (Styling) +- Drizzle ORM (Database) +- Modern UI Components + +**Infrastructure:** +- Docker & Docker Compose +- Caddy (Reverse Proxy) +- Prometheus (Monitoring) +- Grafana (Dashboards) + +## 🚀 Schnellstart + +### Voraussetzungen + +- **Docker** & **Docker Compose** installiert +- **Git** (empfohlen fĂŒr Entwicklung) +- **4GB RAM** und **10GB freier Speicherplatz** +- **PowerShell 5.1+** (Windows) oder **Bash 4.0+** (Linux/macOS) + +### Installation + +1. **Repository klonen** + ```bash + git clone + cd Projektarbeit-MYP + ``` + +2. **System starten** + + **Windows:** + ```powershell + # Einfacher Start (Entwicklungsumgebung) + .\start.ps1 + + # Mit Optionen + .\start.ps1 -Help # Hilfe anzeigen + .\start.ps1 prod # Produktionsumgebung + .\start.ps1 dev -Clean # Mit Bereinigung + ``` + + **Linux/macOS:** + ```bash + # AusfĂŒhrungsrechte setzen (einmalig) + chmod +x start.sh cleanup.sh + + # Einfacher Start (Entwicklungsumgebung) + ./start.sh + + # Mit Optionen + ./start.sh --help # Hilfe anzeigen + ./start.sh prod # Produktionsumgebung + ./start.sh dev --clean # Mit Bereinigung + ``` + +3. **Zugriff auf die Anwendung** + - 🌐 **Web Interface**: http://localhost + - 🔧 **Backend API**: http://localhost/api + - ⚛ **Frontend Dev**: http://localhost:3000 (nur Entwicklung) + +## 📋 VerfĂŒgbare Umgebungen + +### đŸ› ïž Entwicklung (Standard) +```bash +# Windows +.\start.ps1 dev + +# Linux/macOS +./start.sh dev +``` + +**Features:** +- Hot Reload fĂŒr Frontend und Backend +- Debug-Server auf Port 5555 (Backend) und 8081 (Frontend) +- Monitoring: Prometheus (9090), Grafana (3001) +- Datenbank-Viewer: Adminer (8080) +- Redis Cache (6379) +- Entwickler-Tools aktiviert + +### 🚀 Produktion +```bash +# Windows +.\start.ps1 prod + +# Linux/macOS +./start.sh prod +``` + +**Features:** +- Optimierte Container-Images +- SSL-VerschlĂŒsselung (Let's Encrypt) +- Performance-Optimierungen +- Sicherheitsheader +- Automatische Backups +- Health Checks + +### đŸ§Ș Test +```bash +# Windows +.\start.ps1 test + +# Linux/macOS +./start.sh test +``` + +**Features:** +- In-Memory-Datenbank +- Mock-Services +- Test-Fixtures +- Coverage-Reports +- Automatisierte Tests + +## đŸ› ïž Entwicklung + +### Projektstruktur + +``` +Projektarbeit-MYP/ +├── đŸ–„ïž backend/ # Flask API Server +│ ├── app.py # Hauptanwendung +│ ├── config.py # Konfiguration +│ ├── security.py # Sicherheitsmodule +│ ├── monitoring.py # Monitoring & Logging +│ ├── requirements.txt # Python-AbhĂ€ngigkeiten +│ ├── Dockerfile # Produktions-Container +│ ├── Dockerfile.dev # Entwicklungs-Container +│ ├── instance/ # Datenbank & Uploads +│ ├── logs/ # Anwendungslogs +│ ├── migrations/ # Datenbankmigrationen +│ ├── static/ # Statische Dateien +│ └── templates/ # HTML-Templates +│ +├── 🌐 frontend/ # Next.js Web Interface +│ ├── src/ # Quellcode +│ │ ├── app/ # App Router (Next.js 14) +│ │ ├── components/ # React-Komponenten +│ │ ├── server/ # Server-seitige Logik +│ │ └── utils/ # Hilfsfunktionen +│ ├── public/ # Öffentliche Dateien +│ ├── package.json # Node.js-AbhĂ€ngigkeiten +│ ├── Dockerfile # Produktions-Container +│ ├── Dockerfile.dev # Entwicklungs-Container +│ ├── tailwind.config.ts # Tailwind-Konfiguration +│ ├── tsconfig.json # TypeScript-Konfiguration +│ └── drizzle/ # Datenbank-Schema +│ +├── 🔄 proxy/ # Caddy Reverse Proxy +│ └── Caddyfile # Proxy-Konfiguration +│ +├── 📊 monitoring/ # Prometheus & Grafana +│ ├── prometheus/ # Monitoring-Konfiguration +│ └── grafana/ # Dashboard-Konfiguration +│ +├── 🔧 infrastructure/ # Deployment & Konfiguration +│ ├── scripts/ # Deployment-Skripte +│ │ ├── start.ps1 # Windows-Startskript +│ │ ├── start.sh # Linux/macOS-Startskript +│ │ ├── cleanup.ps1 # Windows-Bereinigung +│ │ └── cleanup.sh # Linux/macOS-Bereinigung +│ └── environments/ # Umgebungskonfigurationen +│ ├── development.env # Entwicklungsumgebung +│ ├── production.env # Produktionsumgebung +│ └── test.env # Testumgebung +│ +├── đŸ§Ș tests/ # Übergreifende Tests +│ ├── e2e/ # End-to-End-Tests +│ └── integration/ # Integrationstests +│ +├── 📚 docs/ # Projektdokumentation +├── 📝 logs/ # Systemlogs +├── 🐳 docker-compose.yml # Hauptkonfiguration +├── 🐳 docker-compose.dev.yml # Entwicklungskonfiguration +├── 📋 README.md # Diese Datei +├── 📋 PROJECT_STRUCTURE.md # Detaillierte Architektur +├── 📋 Dokumentation.md # Deutsche Dokumentation +└── 📄 LICENSE.md # Lizenzinformationen +``` + +### Backend-Entwicklung + +```bash +cd backend + +# Virtuelle Umgebung erstellen +python -m venv venv + +# Aktivieren +source venv/bin/activate # Linux/macOS +venv\Scripts\activate # Windows + +# AbhĂ€ngigkeiten installieren +pip install -r requirements.txt + +# Entwicklungsserver starten +flask run --debug --host=0.0.0.0 --port=5000 +``` + +### Frontend-Entwicklung + +```bash +cd frontend + +# AbhĂ€ngigkeiten installieren +pnpm install + +# Entwicklungsserver starten +pnpm dev + +# Build fĂŒr Produktion +pnpm build + +# Linting & Formatierung +pnpm lint +pnpm format +``` + +### API-Dokumentation + +Die API-Dokumentation ist verfĂŒgbar unter: +- **Swagger UI**: http://localhost/api/docs +- **OpenAPI Spec**: http://localhost/api/swagger.json +- **Redoc**: http://localhost/api/redoc + +## 🔧 Konfiguration + +### Umgebungsvariablen + +Konfigurationsdateien befinden sich in `infrastructure/environments/`: + +- `development.env` - Entwicklungsumgebung +- `production.env` - Produktionsumgebung +- `test.env` - Testumgebung + +### Drucker-Konfiguration + +Drucker werden ĂŒber die `PRINTERS` Umgebungsvariable konfiguriert: + +```json +{ + "Drucker 1": { + "ip": "192.168.0.100", + "model": "UltiMaker S5", + "location": "Raum A.1.01" + }, + "Drucker 2": { + "ip": "192.168.0.101", + "model": "UltiMaker S5", + "location": "Raum A.1.02" + } +} +``` + +### TAPO Smart Plug Integration + +```env +TAPO_USERNAME=your-email@example.com +TAPO_PASSWORD=your-secure-password +``` + +### SSL/TLS-Konfiguration (Produktion) + +```env +CADDY_DOMAIN=your-domain.com +CADDY_EMAIL=admin@your-domain.com +SSL_ENABLED=true +``` + +## đŸ§č Wartung + +### System bereinigen + +**Windows:** +```powershell +# Interaktive Bereinigung +.\cleanup.ps1 + +# Automatische Bereinigung +.\cleanup.ps1 -Force + +# VollstĂ€ndige Bereinigung (inkl. Volumes) +.\cleanup.ps1 -All -Force +``` + +**Linux/macOS:** +```bash +# Interaktive Bereinigung +./cleanup.sh + +# Automatische Bereinigung +./cleanup.sh --force + +# VollstĂ€ndige Bereinigung (inkl. Volumes) +./cleanup.sh --all --force +``` + +### Logs anzeigen + +```bash +# Alle Services +docker-compose logs -f + +# Spezifische Services +docker-compose logs -f backend +docker-compose logs -f frontend +docker-compose logs -f caddy + +# Mit Zeitstempel +docker-compose logs -f -t +``` + +### Container-Status prĂŒfen + +```bash +# Status aller Container +docker-compose ps + +# Detaillierte Informationen +docker-compose top + +# Ressourcenverbrauch +docker stats + +# Health Checks +docker-compose exec backend curl -f http://localhost:5000/health +docker-compose exec frontend curl -f http://localhost:3000/api/health +``` + +### Backup & Restore + +```bash +# Datenbank-Backup erstellen +docker-compose exec backend python -c " +import sqlite3 +import shutil +shutil.copy('instance/myp.db', 'instance/backup_$(date +%Y%m%d_%H%M%S).db') +" + +# Logs archivieren +tar -czf logs_backup_$(date +%Y%m%d_%H%M%S).tar.gz logs/ +``` + +## 🔒 Sicherheit + +### Produktionsumgebung + +- **SSL/TLS**: Automatische Let's Encrypt-Zertifikate +- **Security Headers**: HSTS, CSP, X-Frame-Options +- **Rate Limiting**: API-Endpunkt-Schutz +- **Authentication**: JWT-basierte Authentifizierung +- **Input Validation**: Umfassende Eingabevalidierung +- **CORS**: Konfigurierbare Cross-Origin-Richtlinien + +### Geheimnisse verwalten + +```bash +# Sichere Umgebungsvariablen setzen +echo "SECRET_KEY=$(openssl rand -hex 32)" >> infrastructure/environments/production.env +echo "JWT_SECRET=$(openssl rand -hex 32)" >> infrastructure/environments/production.env +``` + +## 🚹 Fehlerbehebung + +### HĂ€ufige Probleme + +**Docker-Container starten nicht:** +```bash +# Docker-Status prĂŒfen +docker info + +# Container-Logs anzeigen +docker-compose logs + +# Ports prĂŒfen +netstat -tulpn | grep :80 +netstat -tulpn | grep :3000 +netstat -tulpn | grep :5000 +``` + +**Frontend kann Backend nicht erreichen:** +```bash +# Netzwerk-Konfiguration prĂŒfen +docker network ls +docker network inspect projektarbeit-myp_myp-network + +# API-Erreichbarkeit testen +curl -f http://localhost/api/health +``` + +**Datenbank-Probleme:** +```bash +# Datenbank-IntegritĂ€t prĂŒfen +docker-compose exec backend python -c " +import sqlite3 +conn = sqlite3.connect('instance/myp.db') +conn.execute('PRAGMA integrity_check;') +print(conn.fetchall()) +" +``` + +### Support + +Bei Problemen: +1. PrĂŒfen Sie die Logs: `docker-compose logs` +2. ÜberprĂŒfen Sie die Systemvoraussetzungen +3. FĂŒhren Sie eine Bereinigung durch: `./cleanup.sh --force` +4. Starten Sie das System neu: `./start.sh` + +## 📈 Performance + +### Monitoring + +- **Prometheus**: http://localhost:9090 (nur Entwicklung) +- **Grafana**: http://localhost:3001 (nur Entwicklung) +- **Caddy Admin**: http://localhost:2019 + +### Optimierungen + +- **Container-Images**: Multi-Stage-Builds fĂŒr minimale GrĂ¶ĂŸe +- **Caching**: Redis fĂŒr Session-Management +- **CDN**: Statische Assets ĂŒber Caddy +- **Database**: SQLite mit WAL-Modus fĂŒr bessere Performance + +## đŸ€ Beitragen + +1. Fork des Repositories erstellen +2. Feature-Branch erstellen: `git checkout -b feature/neue-funktion` +3. Änderungen committen: `git commit -am 'Neue Funktion hinzufĂŒgen'` +4. Branch pushen: `git push origin feature/neue-funktion` +5. Pull Request erstellen + +## 📄 Lizenz + +Dieses Projekt steht unter der MIT-Lizenz. Siehe [LICENSE.md](LICENSE.md) fĂŒr Details. + +## 🙏 Danksagungen + +- **TBA Werk 040** - FĂŒr die UnterstĂŒtzung und Anforderungen +- **Open Source Community** - FĂŒr die verwendeten Technologien +- **Docker Team** - FĂŒr die Container-Technologie +- **Next.js Team** - FĂŒr das Frontend-Framework +- **Flask Team** - FĂŒr das Backend-Framework --- -# Datenbankstruktur - -(MYP.sql - GerĂ€t: Reservation Pi) - -### Printer - -- Speichert Informationen zu Druckern. -- Beinhaltet Details wie Namen, Beschreibung und Betriebsstatus. -- VerknĂŒpft mit DruckauftrĂ€gen. - -### PrintJob - -- EnthĂ€lt alle DruckauftrĂ€ge. -- Jeder Auftrag ist einem Drucker und einem Benutzer zugeordnet. -- Speichert Startzeit, Dauer und Kommentare zu den AuftrĂ€gen. -- Erfassung, ob ein Auftrag abgebrochen wurde und die dazugehörige BegrĂŒndung. - -### Account - -- Verwaltet Benutzerkonten. -- Speichert Authentifizierungsdetails wie Tokens und deren Ablaufzeiten. - -### Session - -- Erfasst Session-Daten. -- Beinhaltet eindeutige Session-Tokens und Ablaufdaten. - -### User - -- Speichert Benutzerinformationen. -- VerknĂŒpft mit DruckauftrĂ€gen, Accounts und Sessions. - -## FremdschlĂŒsselbeziehungen - -- `User` ist verknĂŒpft mit `PrintJob`, `Account` und `Session` ĂŒber Benutzer-ID. -- `Printer` ist verknĂŒpft mit `PrintJob` ĂŒber die Drucker-ID. - -## Installation und Start - -### Windows - -1. Stellen Sie sicher, dass Docker Desktop installiert und gestartet ist. -2. Öffnen Sie PowerShell und navigieren Sie zum Projektverzeichnis. -3. FĂŒhren Sie das Start-Skript aus: - ``` - .\start.ps1 - ``` - -### Linux/Mac - -1. Stellen Sie sicher, dass Docker installiert und gestartet ist. -2. Öffnen Sie ein Terminal und navigieren Sie zum Projektverzeichnis. -3. Machen Sie die Skripte ausfĂŒhrbar: - ``` - chmod +x start.sh cleanup.sh - ``` -4. FĂŒhren Sie das Start-Skript aus: - ``` - ./start.sh - ``` - -## Bereinigung der Umgebung - -Um eine vollstĂ€ndige Bereinigung aller Container, Images und Volumes durchzufĂŒhren, können Sie folgende Skripte verwenden: - -### Windows - -``` -.\cleanup.ps1 -``` - -### Linux/Mac - -``` -./cleanup.sh -``` - -Die Bereinigung kann auch wĂ€hrend des Starts der Anwendung durchgefĂŒhrt werden, wenn alte Container erkannt werden. - -## Backend-Interface - -Das Backend-Interface ist unter folgenden URLs erreichbar: - -- Produktionsumgebung: http://localhost:5000 -- Debug-Server: http://localhost:5555 - -## Frontend-Interface - -Das Frontend-Interface ist unter folgenden URLs erreichbar: - -- Produktionsumgebung: http://localhost:80 oder https://localhost:443 -- Debug-Server: http://localhost:8081 - -## SSH-Server - -Die Start-Skripte sorgen automatisch dafĂŒr, dass ein SSH-Server installiert, aktiviert und gestartet wird: - -- Unter Linux: Verwendet systemd, um den OpenSSH-Server zu aktivieren und zu starten -- Unter Windows: Installiert und konfiguriert den Windows OpenSSH-Server - -Der SSH-Server wird so konfiguriert, dass er automatisch beim Systemstart aktiviert wird, um einen Fernzugriff auf das System zu ermöglichen. Auf Windows-Systemen wird auch eine entsprechende Firewall-Regel erstellt. - -### Manuelles Einrichten des SSH-Servers - -Falls die automatische Installation fehlschlĂ€gt: - -#### Linux (Debian/Ubuntu) -``` -sudo apt-get update -sudo apt-get install openssh-server -sudo systemctl enable ssh -sudo systemctl start ssh -``` - -#### Windows 10/11 -1. Öffnen Sie "Einstellungen" > "Apps" > "Optionale Features" -2. Klicken Sie auf "Feature hinzufĂŒgen" und wĂ€hlen Sie "OpenSSH Server" -3. Nach der Installation öffnen Sie PowerShell als Administrator und fĂŒhren Sie folgende Befehle aus: -``` -Set-Service -Name sshd -StartupType Automatic -Start-Service sshd -New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (TCP-In)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -``` +**Entwickelt mit ❀ fĂŒr die TBA im Werk 040, Berlin-Marienfelde** diff --git a/backend/PRODUCTION_SETUP.md b/backend/PRODUCTION_SETUP.md index 0519ecba..ffe4d731 100644 --- a/backend/PRODUCTION_SETUP.md +++ b/backend/PRODUCTION_SETUP.md @@ -1 +1,327 @@ - \ No newline at end of file +# MYP Backend - Produktions-Setup Anleitung + +Diese Anleitung beschreibt die Installation und Konfiguration des MYP Backends fĂŒr den Produktionsbetrieb. + +## Voraussetzungen + +- Linux-Server (Ubuntu 20.04 LTS oder höher empfohlen) +- Python 3.8 oder höher +- Nginx (optional, fĂŒr Reverse Proxy) +- Systemd (fĂŒr Service-Management) + +## Installation + +### 1. System-Updates und AbhĂ€ngigkeiten + +```bash +sudo apt update && sudo apt upgrade -y +sudo apt install python3 python3-pip python3-venv nginx sqlite3 -y +``` + +### 2. Benutzer und Verzeichnisse erstellen + +```bash +# MYP-Benutzer erstellen +sudo useradd --system --group --home /opt/myp myp + +# Verzeichnisse erstellen +sudo mkdir -p /opt/myp/{backend,logs} +sudo chown -R myp:myp /opt/myp +``` + +### 3. Anwendung installieren + +```bash +# Als myp-Benutzer wechseln +sudo -u myp bash + +# In das Backend-Verzeichnis wechseln +cd /opt/myp/backend + +# Repository klonen (oder Dateien kopieren) +# git clone https://github.com/your-org/myp.git . + +# Virtual Environment erstellen +python3 -m venv /opt/myp/venv +source /opt/myp/venv/bin/activate + +# Dependencies installieren +pip install -r requirements.txt +``` + +### 4. Konfiguration + +```bash +# Umgebungsvariablen konfigurieren +cp env.example .env +nano .env + +# Wichtige Konfigurationen: +# - SECRET_KEY: Sicheren SchlĂŒssel generieren +# - TAPO_USERNAME/TAPO_PASSWORD: Tapo-Anmeldedaten +# - PRINTERS: Drucker-Konfiguration als JSON +``` + +#### Beispiel fĂŒr sichere SECRET_KEY-Generierung: + +```bash +python3 -c "import secrets; print(secrets.token_hex(32))" +``` + +### 5. Datenbank initialisieren + +```bash +# Datenbank-Verzeichnis erstellen +mkdir -p instance + +# Flask-Anwendung starten, um Datenbank zu initialisieren +python3 app.py +# Ctrl+C nach erfolgreicher Initialisierung +``` + +### 6. Systemd Service einrichten + +```bash +# Als root-Benutzer +sudo cp myp-backend.service /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable myp-backend +sudo systemctl start myp-backend +``` + +### 7. Service-Status ĂŒberprĂŒfen + +```bash +sudo systemctl status myp-backend +sudo journalctl -u myp-backend -f +``` + +## Nginx Reverse Proxy (Optional) + +### Nginx-Konfiguration erstellen + +```bash +sudo nano /etc/nginx/sites-available/myp-backend +``` + +```nginx +server { + listen 80; + server_name your-domain.com; + + location / { + proxy_pass http://127.0.0.1:5000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_connect_timeout 30; + proxy_send_timeout 30; + proxy_read_timeout 30; + } + + # Statische Dateien direkt ausliefern + location /static/ { + alias /opt/myp/backend/static/; + expires 1h; + add_header Cache-Control "public, immutable"; + } + + # Health Check + location /monitoring/health/simple { + access_log off; + proxy_pass http://127.0.0.1:5000; + } +} +``` + +### Nginx aktivieren + +```bash +sudo ln -s /etc/nginx/sites-available/myp-backend /etc/nginx/sites-enabled/ +sudo nginx -t +sudo systemctl reload nginx +``` + +## SSL/HTTPS Setup (Empfohlen) + +### Mit Let's Encrypt (Certbot) + +```bash +sudo apt install certbot python3-certbot-nginx -y +sudo certbot --nginx -d your-domain.com +``` + +### Umgebungsvariable fĂŒr HTTPS setzen + +```bash +# In .env-Datei +FORCE_HTTPS=true +``` + +## Monitoring und Logs + +### Log-Dateien + +- Anwendungs-Logs: `/opt/myp/backend/logs/myp.log` +- Error-Logs: `/opt/myp/backend/logs/myp-errors.log` +- Security-Logs: `/opt/myp/backend/logs/security.log` +- Systemd-Logs: `journalctl -u myp-backend` + +### Health Check-Endpunkte + +- Einfacher Health Check: `http://your-domain.com/monitoring/health/simple` +- Detaillierter Health Check: `http://your-domain.com/monitoring/health` +- System-Metriken: `http://your-domain.com/monitoring/metrics` +- Anwendungsinfo: `http://your-domain.com/monitoring/info` + +## Wartung und Updates + +### Service neustarten + +```bash +sudo systemctl restart myp-backend +``` + +### Logs rotieren + +Die Log-Rotation ist automatisch konfiguriert. Bei Bedarf manuell: + +```bash +sudo logrotate -f /etc/logrotate.d/myp-backend +``` + +### Updates installieren + +```bash +sudo -u myp bash +cd /opt/myp/backend +source /opt/myp/venv/bin/activate + +# Code aktualisieren +git pull + +# Dependencies aktualisieren +pip install -r requirements.txt --upgrade + +# Service neustarten +sudo systemctl restart myp-backend +``` + +### Datenbank-Backup + +```bash +# Backup erstellen +sudo -u myp sqlite3 /opt/myp/backend/instance/myp.db ".backup /opt/myp/backup/myp_$(date +%Y%m%d_%H%M%S).db" + +# Automatisches Backup via Cron +sudo -u myp crontab -e +# FĂŒge hinzu: 0 2 * * * sqlite3 /opt/myp/backend/instance/myp.db ".backup /opt/myp/backup/myp_$(date +\%Y\%m\%d_\%H\%M\%S).db" +``` + +## Sicherheit + +### Firewall konfigurieren + +```bash +sudo ufw allow ssh +sudo ufw allow 'Nginx Full' +sudo ufw --force enable +``` + +### Fail2Ban fĂŒr zusĂ€tzlichen Schutz + +```bash +sudo apt install fail2ban -y +sudo nano /etc/fail2ban/jail.local +``` + +```ini +[DEFAULT] +bantime = 3600 +findtime = 600 +maxretry = 5 + +[nginx-http-auth] +enabled = true +port = http,https +logpath = /var/log/nginx/error.log +``` + +### RegelmĂ€ĂŸige Security-Updates + +```bash +sudo apt install unattended-upgrades -y +sudo dpkg-reconfigure -plow unattended-upgrades +``` + +## Troubleshooting + +### Service startet nicht + +```bash +# Logs ĂŒberprĂŒfen +sudo journalctl -u myp-backend --no-pager +sudo -u myp cat /opt/myp/backend/logs/myp-errors.log +``` + +### Hohe Speichernutzung + +```bash +# Memory-Statistiken +sudo systemctl status myp-backend +sudo ps aux | grep gunicorn +``` + +### Datenbankprobleme + +```bash +# Datenbank-IntegritĂ€t prĂŒfen +sudo -u myp sqlite3 /opt/myp/backend/instance/myp.db "PRAGMA integrity_check;" +``` + +### Netzwerk-KonnektivitĂ€t + +```bash +# Port-VerfĂŒgbarkeit prĂŒfen +sudo netstat -tlnp | grep :5000 +curl -I http://localhost:5000/monitoring/health/simple +``` + +## Performance-Optimierung + +### Gunicorn Worker anpassen + +```bash +# In .env oder Service-Datei +WORKERS=8 # 2 * CPU-Kerne + 1 +``` + +### Nginx-Caching aktivieren + +```nginx +# In Nginx-Konfiguration +location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { + expires 1y; + add_header Cache-Control "public, immutable"; +} +``` + +### SQLite-Optimierung + +```sql +-- FĂŒr bessere Performance (einmalig ausfĂŒhren) +PRAGMA journal_mode=WAL; +PRAGMA synchronous=NORMAL; +PRAGMA cache_size=10000; +PRAGMA temp_store=memory; +``` + +## Support + +Bei Problemen oder Fragen: + +1. ÜberprĂŒfen Sie die Log-Dateien +2. Testen Sie die Health Check-Endpunkte +3. Konsultieren Sie die Systemd-Logs +4. Kontaktieren Sie das Entwicklungsteam \ No newline at end of file