"Update backend installation scripts for consistency"

This commit is contained in:
Till Tomczak 2025-05-23 09:54:17 +02:00
parent 72230c342d
commit ffc32959e0
3 changed files with 120 additions and 46 deletions

View File

@ -36,6 +36,58 @@ function Write-Error {
Write-Log "FEHLER: $Message" -Color $Red
}
# Verbesserte Funktion zum Parsen der Umgebungsvariablen
function Set-EnvironmentFromFile {
param([string]$FilePath)
if (-not (Test-Path $FilePath)) {
Write-Warning "$FilePath nicht gefunden"
return
}
Write-Log "⚙️ Lade 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
if ([string]::IsNullOrWhiteSpace($Line) -or $Line.TrimStart().StartsWith('#')) {
continue
}
# Finde den ersten = Zeichen
$EqualIndex = $Line.IndexOf('=')
if ($EqualIndex -le 0) {
continue
}
# Extrahiere Key und Value
$Key = $Line.Substring(0, $EqualIndex).Trim()
$Value = $Line.Substring($EqualIndex + 1).Trim()
# Entferne umgebende Anführungszeichen, falls vorhanden
if (($Value.StartsWith('"') -and $Value.EndsWith('"')) -or
($Value.StartsWith("'") -and $Value.EndsWith("'"))) {
$Value = $Value.Substring(1, $Value.Length - 2)
}
# Setze Umgebungsvariable
if (-not [string]::IsNullOrWhiteSpace($Key)) {
[Environment]::SetEnvironmentVariable($Key, $Value, "Process")
Write-Log "Geladen: $Key" -Color $Blue
}
}
Write-Success "Umgebungsvariablen erfolgreich geladen"
} catch {
Write-Error "Fehler beim Laden der Umgebungsvariablen: $_"
Write-Warning "Verwende Standard-Umgebungsvariablen"
}
}
# Banner
Write-Host "========================================" -ForegroundColor $Blue
Write-Host "🏭 MYP Backend - Windows Installation" -ForegroundColor $Blue
@ -158,23 +210,8 @@ if (Test-Path "requirements.txt") {
# Umgebungskonfiguration
Write-Log "⚙️ Konfiguriere Umgebung..." -Color $Blue
if (Test-Path "env.backend") {
Write-Log "Umgebungskonfiguration gefunden: env.backend"
# Lade Umgebungsvariablen für Tests
$EnvContent = Get-Content "env.backend"
foreach ($Line in $EnvContent) {
if ($Line -match "^([^#][^=]+)=(.*)$") {
$Key = $Matches[1].Trim()
$Value = $Matches[2].Trim()
[Environment]::SetEnvironmentVariable($Key, $Value, "Process")
}
}
Write-Success "Umgebungsvariablen geladen"
} else {
Write-Warning "env.backend nicht gefunden"
}
# Lade Umgebungsvariablen für Tests
Set-EnvironmentFromFile "env.backend"
# Datenbank initialisieren
Write-Log "🗄️ Initialisiere Datenbank..." -Color $Blue
@ -226,7 +263,7 @@ Write-Host ""
Write-Host "📋 Nächste Schritte:" -ForegroundColor $Blue
Write-Host "1. Backend starten:" -ForegroundColor $White
Write-Host " .\start-backend-server.ps1" -ForegroundColor $Yellow
Write-Host " .\start-backend-server.ps1 -Development" -ForegroundColor $Yellow
Write-Host ""
Write-Host "2. Health-Check testen:" -ForegroundColor $White
Write-Host " curl http://localhost:5000/monitoring/health/simple" -ForegroundColor $Yellow

View File

@ -120,7 +120,7 @@ install_system_dependencies() {
else
log "Bitte installieren Sie Python 3 manuell für Ihr System"
fi
exit 1
exit 1
fi
# Python-Version prüfen
@ -142,10 +142,10 @@ install_system_dependencies() {
sudo apt install python3-pip
else
error_log "Bitte installieren Sie pip3 manuell"
exit 1
fi
fi
exit 1
fi
fi
# Weitere notwendige System-Pakete prüfen
if [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then
log "Prüfe System-Pakete für Ubuntu/Debian..."

View File

@ -92,26 +92,63 @@ try {
exit 1
}
# Umgebungsvariablen laden
if (Test-Path "env.backend") {
Write-Log "⚙️ Lade Backend-Umgebungsvariablen..." -Color $Blue
# Verbesserte Funktion zum Parsen der Umgebungsvariablen
function Set-EnvironmentFromFile {
param([string]$FilePath)
$EnvContent = Get-Content "env.backend"
foreach ($Line in $EnvContent) {
if ($Line -match "^([^#][^=]+)=(.*)$") {
$Key = $Matches[1].Trim()
$Value = $Matches[2].Trim()
[Environment]::SetEnvironmentVariable($Key, $Value, "Process")
}
if (-not (Test-Path $FilePath)) {
Write-Warning "$FilePath nicht gefunden"
return
}
# Überschreibe FLASK_ENV mit dem gewählten Modus
$env:FLASK_ENV = $RunMode
Write-Success "Umgebungsvariablen geladen"
} else {
Write-Warning "env.backend nicht gefunden"
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
if ([string]::IsNullOrWhiteSpace($Line) -or $Line.TrimStart().StartsWith('#')) {
continue
}
# Finde den ersten = Zeichen
$EqualIndex = $Line.IndexOf('=')
if ($EqualIndex -le 0) {
continue
}
# Extrahiere Key und Value
$Key = $Line.Substring(0, $EqualIndex).Trim()
$Value = $Line.Substring($EqualIndex + 1).Trim()
# Entferne umgebende Anführungszeichen, falls vorhanden
if (($Value.StartsWith('"') -and $Value.EndsWith('"')) -or
($Value.StartsWith("'") -and $Value.EndsWith("'"))) {
$Value = $Value.Substring(1, $Value.Length - 2)
}
# Setze Umgebungsvariable
if (-not [string]::IsNullOrWhiteSpace($Key)) {
[Environment]::SetEnvironmentVariable($Key, $Value, "Process")
Write-Log "Geladen: $Key" -Color $Blue
}
}
# Überschreibe FLASK_ENV mit dem gewählten Modus
[Environment]::SetEnvironmentVariable("FLASK_ENV", $RunMode, "Process")
Write-Success "Umgebungsvariablen erfolgreich geladen"
} catch {
Write-Error "Fehler beim Laden der Umgebungsvariablen: $_"
Write-Warning "Verwende Standard-Umgebungsvariablen"
}
}
# Umgebungsvariablen laden
Set-EnvironmentFromFile "env.backend"
# Notwendige Verzeichnisse erstellen
Write-Log "📁 Prüfe Verzeichnisse..." -Color $Blue
@ -212,7 +249,7 @@ if ($RunMode -eq "production") {
# Warte auf Server-Start
Write-Log "Warte auf Backend-Service..." -Color $Blue
$Counter = 0
$Timeout = 60
$TimeoutSeconds = 60
do {
Start-Sleep -Seconds 1
@ -229,11 +266,11 @@ if ($RunMode -eq "production") {
}
if ($Counter % 10 -eq 0) {
Write-Log "Warte auf Backend-Service... ($Counter/$Timeout Sekunden)"
Write-Log "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
}
} while ($Counter -lt $Timeout)
} while ($Counter -lt $TimeoutSeconds)
if ($Counter -eq $Timeout) {
if ($Counter -eq $TimeoutSeconds) {
Write-Error "Backend-Service konnte nicht gestartet werden!"
exit 1
}
@ -259,7 +296,7 @@ if ($RunMode -eq "production") {
# Warte auf Server-Start
Write-Log "Warte auf Backend-Service..." -Color $Blue
$Counter = 0
$Timeout = 60
$TimeoutSeconds = 60
do {
Start-Sleep -Seconds 1
@ -276,11 +313,11 @@ if ($RunMode -eq "production") {
}
if ($Counter % 10 -eq 0) {
Write-Log "Warte auf Backend-Service... ($Counter/$Timeout Sekunden)"
Write-Log "Warte auf Backend-Service... ($Counter/$TimeoutSeconds Sekunden)"
}
} while ($Counter -lt $Timeout)
} while ($Counter -lt $TimeoutSeconds)
if ($Counter -eq $Timeout) {
if ($Counter -eq $TimeoutSeconds) {
Write-Error "Backend-Service konnte nicht gestartet werden!"
if ($FlaskProcess -and !$FlaskProcess.HasExited) {
$FlaskProcess.Kill()