"feat: Implement backend server initialization with temp init script"
This commit is contained in:
parent
ffc32959e0
commit
ed2765d207
@ -1,5 +1,5 @@
|
||||
# MYP Backend - Windows PowerShell Server Start
|
||||
# Startet den Backend-Server vollständig unabhängig vom Frontend
|
||||
# Startet den Backend-Server vollstaendig unabhaengig vom Frontend
|
||||
|
||||
param(
|
||||
[switch]$Production,
|
||||
@ -8,7 +8,7 @@ param(
|
||||
[switch]$Help
|
||||
)
|
||||
|
||||
# Farben für PowerShell
|
||||
# Farben fuer PowerShell
|
||||
$Red = "Red"
|
||||
$Green = "Green"
|
||||
$Yellow = "Yellow"
|
||||
@ -37,51 +37,49 @@ function Write-Error {
|
||||
|
||||
# Banner
|
||||
Write-Host "========================================" -ForegroundColor $Blue
|
||||
Write-Host "🏭 MYP Backend - Standalone Server Start" -ForegroundColor $Blue
|
||||
Write-Host "MYP Backend - Standalone Server Start" -ForegroundColor $Blue
|
||||
Write-Host "========================================" -ForegroundColor $Blue
|
||||
|
||||
if ($Help) {
|
||||
Write-Host @"
|
||||
Verwendung: .\start-backend-server.ps1 [OPTIONEN]
|
||||
|
||||
OPTIONEN:
|
||||
-Production Produktionsmodus (Gunicorn)
|
||||
-Development Entwicklungsmodus (Flask Dev Server)
|
||||
-Logs Zeige Live-Logs
|
||||
-Help Zeige diese Hilfe
|
||||
|
||||
BEISPIELE:
|
||||
.\start-backend-server.ps1 -Development
|
||||
.\start-backend-server.ps1 -Production
|
||||
.\start-backend-server.ps1 -Development -Logs
|
||||
"@
|
||||
Write-Host "Verwendung: .\start-backend-server.ps1 [OPTIONEN]"
|
||||
Write-Host ""
|
||||
Write-Host "OPTIONEN:"
|
||||
Write-Host " -Production Produktionsmodus (Gunicorn)"
|
||||
Write-Host " -Development Entwicklungsmodus (Flask Dev Server)"
|
||||
Write-Host " -Logs Zeige Live-Logs"
|
||||
Write-Host " -Help Zeige diese Hilfe"
|
||||
Write-Host ""
|
||||
Write-Host "BEISPIELE:"
|
||||
Write-Host " .\start-backend-server.ps1 -Development"
|
||||
Write-Host " .\start-backend-server.ps1 -Production"
|
||||
Write-Host " .\start-backend-server.ps1 -Development -Logs"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Bestimme Ausführungsmodus
|
||||
# Bestimme Ausfuehrungsmodus
|
||||
$RunMode = "development"
|
||||
if ($Production) {
|
||||
$RunMode = "production"
|
||||
Write-Log "🏭 Produktionsmodus aktiviert" -Color $Blue
|
||||
Write-Log "Produktionsmodus aktiviert" -Color $Blue
|
||||
} elseif ($Development) {
|
||||
$RunMode = "development"
|
||||
Write-Log "🔧 Entwicklungsmodus aktiviert" -Color $Blue
|
||||
Write-Log "Entwicklungsmodus aktiviert" -Color $Blue
|
||||
} else {
|
||||
$RunMode = "development"
|
||||
Write-Log "🔧 Standard-Entwicklungsmodus aktiviert" -Color $Blue
|
||||
Write-Log "Standard-Entwicklungsmodus aktiviert" -Color $Blue
|
||||
}
|
||||
|
||||
# Arbeitsverzeichnis prüfen
|
||||
# Arbeitsverzeichnis pruefen
|
||||
$CurrentDir = Get-Location
|
||||
Write-Log "Arbeitsverzeichnis: $CurrentDir"
|
||||
|
||||
if (-not (Test-Path "app.py")) {
|
||||
Write-Error "app.py nicht gefunden! Bitte im Backend-Verzeichnis ausführen."
|
||||
Write-Error "app.py nicht gefunden! Bitte im Backend-Verzeichnis ausfuehren."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Python-Installation prüfen
|
||||
Write-Log "🐍 Prüfe Python-Installation..." -Color $Blue
|
||||
# Python-Installation pruefen
|
||||
Write-Log "Pruefe Python-Installation..." -Color $Blue
|
||||
|
||||
try {
|
||||
$PythonVersion = python --version 2>&1
|
||||
@ -101,14 +99,14 @@ function Set-EnvironmentFromFile {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Log "⚙️ Lade Backend-Umgebungsvariablen aus $FilePath..." -Color $Blue
|
||||
Write-Log "Lade Backend-Umgebungsvariablen aus $FilePath..." -Color $Blue
|
||||
|
||||
try {
|
||||
$EnvContent = Get-Content $FilePath -Raw
|
||||
$Lines = $EnvContent -split "`r?`n"
|
||||
|
||||
foreach ($Line in $Lines) {
|
||||
# Überspringe leere Zeilen und Kommentare
|
||||
# Ueberspringe leere Zeilen und Kommentare
|
||||
if ([string]::IsNullOrWhiteSpace($Line) -or $Line.TrimStart().StartsWith('#')) {
|
||||
continue
|
||||
}
|
||||
@ -123,7 +121,7 @@ function Set-EnvironmentFromFile {
|
||||
$Key = $Line.Substring(0, $EqualIndex).Trim()
|
||||
$Value = $Line.Substring($EqualIndex + 1).Trim()
|
||||
|
||||
# Entferne umgebende Anführungszeichen, falls vorhanden
|
||||
# Entferne umgebende Anfuehrungszeichen, falls vorhanden
|
||||
if (($Value.StartsWith('"') -and $Value.EndsWith('"')) -or
|
||||
($Value.StartsWith("'") -and $Value.EndsWith("'"))) {
|
||||
$Value = $Value.Substring(1, $Value.Length - 2)
|
||||
@ -136,7 +134,7 @@ function Set-EnvironmentFromFile {
|
||||
}
|
||||
}
|
||||
|
||||
# Überschreibe FLASK_ENV mit dem gewählten Modus
|
||||
# Ueberschreibe FLASK_ENV mit dem gewaehlten Modus
|
||||
[Environment]::SetEnvironmentVariable("FLASK_ENV", $RunMode, "Process")
|
||||
Write-Success "Umgebungsvariablen erfolgreich geladen"
|
||||
|
||||
@ -150,7 +148,7 @@ function Set-EnvironmentFromFile {
|
||||
Set-EnvironmentFromFile "env.backend"
|
||||
|
||||
# Notwendige Verzeichnisse erstellen
|
||||
Write-Log "📁 Prüfe Verzeichnisse..." -Color $Blue
|
||||
Write-Log "Pruefe Verzeichnisse..." -Color $Blue
|
||||
|
||||
$Directories = @("instance", "logs", "uploads")
|
||||
foreach ($Dir in $Directories) {
|
||||
@ -160,8 +158,8 @@ foreach ($Dir in $Directories) {
|
||||
}
|
||||
}
|
||||
|
||||
# Dependencies prüfen
|
||||
Write-Log "📦 Prüfe Python-Dependencies..." -Color $Blue
|
||||
# Dependencies pruefen
|
||||
Write-Log "Pruefe Python-Dependencies..." -Color $Blue
|
||||
|
||||
if (Test-Path "requirements.txt") {
|
||||
try {
|
||||
@ -175,20 +173,18 @@ if (Test-Path "requirements.txt") {
|
||||
}
|
||||
|
||||
# Datenbank initialisieren
|
||||
Write-Log "🗄️ Initialisiere Datenbank..." -Color $Blue
|
||||
Write-Log "Initialisiere Datenbank..." -Color $Blue
|
||||
|
||||
try {
|
||||
$env:FLASK_APP = "app.py"
|
||||
|
||||
# Erstelle temporäre Python-Datei für Datenbank-Initialisierung
|
||||
# Erstelle temporaere Python-Datei fuer Datenbank-Initialisierung
|
||||
$TempInitFile = "temp_init.py"
|
||||
$InitCode = @"
|
||||
from app import create_app, init_db
|
||||
app = create_app('$RunMode')
|
||||
with app.app_context():
|
||||
init_db()
|
||||
print('✅ Datenbank initialisiert')
|
||||
"@
|
||||
$InitCode = "from app import create_app, init_db`n"
|
||||
$InitCode += "app = create_app('$RunMode')`n"
|
||||
$InitCode += "with app.app_context():`n"
|
||||
$InitCode += " init_db()`n"
|
||||
$InitCode += " print('Datenbank initialisiert')"
|
||||
|
||||
$InitCode | Out-File -FilePath $TempInitFile -Encoding UTF8
|
||||
python $TempInitFile
|
||||
@ -203,7 +199,7 @@ with app.app_context():
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Port prüfen
|
||||
# Port pruefen
|
||||
$Port = 5000
|
||||
if ($env:PORT) {
|
||||
$Port = [int]$env:PORT
|
||||
@ -218,12 +214,12 @@ if ($PortInUse) {
|
||||
|
||||
# Server starten basierend auf Modus
|
||||
if ($RunMode -eq "production") {
|
||||
Write-Log "🏭 Starte Backend-Server im Produktionsmodus..." -Color $Blue
|
||||
Write-Log "Starte Backend-Server im Produktionsmodus..." -Color $Blue
|
||||
|
||||
# Prüfe Gunicorn
|
||||
# Pruefe Gunicorn
|
||||
try {
|
||||
gunicorn --version | Out-Null
|
||||
Write-Log "Verwende Gunicorn für Produktionsbetrieb"
|
||||
Write-Log "Verwende Gunicorn fuer Produktionsbetrieb"
|
||||
} catch {
|
||||
Write-Error "Gunicorn ist nicht installiert! Installiere mit: pip install gunicorn"
|
||||
exit 1
|
||||
@ -262,11 +258,12 @@ if ($RunMode -eq "production") {
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
# Ignoriere Fehler während der Startphase
|
||||
# Ignoriere Fehler waehrend der Startphase
|
||||
}
|
||||
|
||||
if ($Counter % 10 -eq 0) {
|
||||
Write-Log "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
|
||||
$StatusMessage = "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
|
||||
Write-Log $StatusMessage
|
||||
}
|
||||
} while ($Counter -lt $TimeoutSeconds)
|
||||
|
||||
@ -277,7 +274,7 @@ if ($RunMode -eq "production") {
|
||||
}
|
||||
|
||||
} else {
|
||||
Write-Log "🔧 Starte Backend-Server im Entwicklungsmodus..." -Color $Blue
|
||||
Write-Log "Starte Backend-Server im Entwicklungsmodus..." -Color $Blue
|
||||
|
||||
# Flask-Entwicklungsserver
|
||||
$env:FLASK_APP = "app.py"
|
||||
@ -309,11 +306,12 @@ if ($RunMode -eq "production") {
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
# Ignoriere Fehler während der Startphase
|
||||
# Ignoriere Fehler waehrend der Startphase
|
||||
}
|
||||
|
||||
if ($Counter % 10 -eq 0) {
|
||||
Write-Log "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
|
||||
$StatusMessage = "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
|
||||
Write-Log $StatusMessage
|
||||
}
|
||||
} while ($Counter -lt $TimeoutSeconds)
|
||||
|
||||
@ -329,22 +327,22 @@ if ($RunMode -eq "production") {
|
||||
|
||||
# URLs anzeigen
|
||||
Write-Host ""
|
||||
Write-Success "🎉 Backend-Server erfolgreich gestartet!"
|
||||
Write-Success "Backend-Server erfolgreich gestartet!"
|
||||
Write-Host ""
|
||||
Write-Host "📡 Backend-API: http://localhost:$Port" -ForegroundColor $Green
|
||||
Write-Host "🔧 Backend-Health: http://localhost:$Port/monitoring/health/simple" -ForegroundColor $Green
|
||||
Write-Host "📋 Backend-Test: http://localhost:$Port/api/test" -ForegroundColor $Green
|
||||
Write-Host "Backend-API: http://localhost:$Port" -ForegroundColor $Green
|
||||
Write-Host "Backend-Health: http://localhost:$Port/monitoring/health/simple" -ForegroundColor $Green
|
||||
Write-Host "Backend-Test: http://localhost:$Port/api/test" -ForegroundColor $Green
|
||||
Write-Host ""
|
||||
|
||||
if ($RunMode -eq "development") {
|
||||
Write-Host "🔧 Entwicklungsmodus aktiv:" -ForegroundColor $Blue
|
||||
Write-Host "Entwicklungsmodus aktiv:" -ForegroundColor $Blue
|
||||
Write-Host "- Debug-Modus ist aktiviert" -ForegroundColor $White
|
||||
Write-Host "- Automatisches Neuladen bei Änderungen" -ForegroundColor $White
|
||||
Write-Host "- Automatisches Neuladen bei Aenderungen" -ForegroundColor $White
|
||||
Write-Host "- Detaillierte Fehlermeldungen" -ForegroundColor $White
|
||||
} else {
|
||||
Write-Host "🏭 Produktionsmodus aktiv:" -ForegroundColor $Blue
|
||||
Write-Host "Produktionsmodus aktiv:" -ForegroundColor $Blue
|
||||
Write-Host "- Gunicorn mit $Workers Workern" -ForegroundColor $White
|
||||
Write-Host "- Optimiert für Performance" -ForegroundColor $White
|
||||
Write-Host "- Optimiert fuer Performance" -ForegroundColor $White
|
||||
Write-Host "- Logging aktiviert" -ForegroundColor $White
|
||||
}
|
||||
|
||||
|
5
backend/temp_init.py
Normal file
5
backend/temp_init.py
Normal file
@ -0,0 +1,5 @@
|
||||
from app import create_app, init_db
|
||||
app = create_app('development')
|
||||
with app.app_context():
|
||||
init_db()
|
||||
print('Datenbank initialisiert')
|
Loading…
x
Reference in New Issue
Block a user