"Update backend installation scripts for consistency"
This commit is contained in:
parent
72230c342d
commit
ffc32959e0
@ -36,6 +36,58 @@ function Write-Error {
|
|||||||
Write-Log "FEHLER: $Message" -Color $Red
|
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
|
# Banner
|
||||||
Write-Host "========================================" -ForegroundColor $Blue
|
Write-Host "========================================" -ForegroundColor $Blue
|
||||||
Write-Host "🏭 MYP Backend - Windows Installation" -ForegroundColor $Blue
|
Write-Host "🏭 MYP Backend - Windows Installation" -ForegroundColor $Blue
|
||||||
@ -158,23 +210,8 @@ if (Test-Path "requirements.txt") {
|
|||||||
# Umgebungskonfiguration
|
# Umgebungskonfiguration
|
||||||
Write-Log "⚙️ Konfiguriere Umgebung..." -Color $Blue
|
Write-Log "⚙️ Konfiguriere Umgebung..." -Color $Blue
|
||||||
|
|
||||||
if (Test-Path "env.backend") {
|
# Lade Umgebungsvariablen für Tests
|
||||||
Write-Log "Umgebungskonfiguration gefunden: env.backend"
|
Set-EnvironmentFromFile "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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Datenbank initialisieren
|
# Datenbank initialisieren
|
||||||
Write-Log "🗄️ Initialisiere Datenbank..." -Color $Blue
|
Write-Log "🗄️ Initialisiere Datenbank..." -Color $Blue
|
||||||
@ -226,7 +263,7 @@ Write-Host ""
|
|||||||
|
|
||||||
Write-Host "📋 Nächste Schritte:" -ForegroundColor $Blue
|
Write-Host "📋 Nächste Schritte:" -ForegroundColor $Blue
|
||||||
Write-Host "1. Backend starten:" -ForegroundColor $White
|
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 ""
|
||||||
Write-Host "2. Health-Check testen:" -ForegroundColor $White
|
Write-Host "2. Health-Check testen:" -ForegroundColor $White
|
||||||
Write-Host " curl http://localhost:5000/monitoring/health/simple" -ForegroundColor $Yellow
|
Write-Host " curl http://localhost:5000/monitoring/health/simple" -ForegroundColor $Yellow
|
||||||
|
@ -144,7 +144,7 @@ install_system_dependencies() {
|
|||||||
error_log "Bitte installieren Sie pip3 manuell"
|
error_log "Bitte installieren Sie pip3 manuell"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Weitere notwendige System-Pakete prüfen
|
# Weitere notwendige System-Pakete prüfen
|
||||||
if [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then
|
if [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then
|
||||||
|
@ -92,26 +92,63 @@ try {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Umgebungsvariablen laden
|
# Verbesserte Funktion zum Parsen der Umgebungsvariablen
|
||||||
if (Test-Path "env.backend") {
|
function Set-EnvironmentFromFile {
|
||||||
Write-Log "⚙️ Lade Backend-Umgebungsvariablen..." -Color $Blue
|
param([string]$FilePath)
|
||||||
|
|
||||||
$EnvContent = Get-Content "env.backend"
|
if (-not (Test-Path $FilePath)) {
|
||||||
foreach ($Line in $EnvContent) {
|
Write-Warning "$FilePath nicht gefunden"
|
||||||
if ($Line -match "^([^#][^=]+)=(.*)$") {
|
return
|
||||||
$Key = $Matches[1].Trim()
|
}
|
||||||
$Value = $Matches[2].Trim()
|
|
||||||
|
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")
|
[Environment]::SetEnvironmentVariable($Key, $Value, "Process")
|
||||||
|
Write-Log "Geladen: $Key" -Color $Blue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Überschreibe FLASK_ENV mit dem gewählten Modus
|
# Überschreibe FLASK_ENV mit dem gewählten Modus
|
||||||
$env:FLASK_ENV = $RunMode
|
[Environment]::SetEnvironmentVariable("FLASK_ENV", $RunMode, "Process")
|
||||||
Write-Success "Umgebungsvariablen geladen"
|
Write-Success "Umgebungsvariablen erfolgreich geladen"
|
||||||
} else {
|
|
||||||
Write-Warning "env.backend nicht gefunden"
|
} catch {
|
||||||
|
Write-Error "Fehler beim Laden der Umgebungsvariablen: $_"
|
||||||
|
Write-Warning "Verwende Standard-Umgebungsvariablen"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Umgebungsvariablen laden
|
||||||
|
Set-EnvironmentFromFile "env.backend"
|
||||||
|
|
||||||
# Notwendige Verzeichnisse erstellen
|
# Notwendige Verzeichnisse erstellen
|
||||||
Write-Log "📁 Prüfe Verzeichnisse..." -Color $Blue
|
Write-Log "📁 Prüfe Verzeichnisse..." -Color $Blue
|
||||||
|
|
||||||
@ -212,7 +249,7 @@ if ($RunMode -eq "production") {
|
|||||||
# Warte auf Server-Start
|
# Warte auf Server-Start
|
||||||
Write-Log "Warte auf Backend-Service..." -Color $Blue
|
Write-Log "Warte auf Backend-Service..." -Color $Blue
|
||||||
$Counter = 0
|
$Counter = 0
|
||||||
$Timeout = 60
|
$TimeoutSeconds = 60
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
@ -229,11 +266,11 @@ if ($RunMode -eq "production") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($Counter % 10 -eq 0) {
|
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!"
|
Write-Error "Backend-Service konnte nicht gestartet werden!"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -259,7 +296,7 @@ if ($RunMode -eq "production") {
|
|||||||
# Warte auf Server-Start
|
# Warte auf Server-Start
|
||||||
Write-Log "Warte auf Backend-Service..." -Color $Blue
|
Write-Log "Warte auf Backend-Service..." -Color $Blue
|
||||||
$Counter = 0
|
$Counter = 0
|
||||||
$Timeout = 60
|
$TimeoutSeconds = 60
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
@ -276,11 +313,11 @@ if ($RunMode -eq "production") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($Counter % 10 -eq 0) {
|
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!"
|
Write-Error "Backend-Service konnte nicht gestartet werden!"
|
||||||
if ($FlaskProcess -and !$FlaskProcess.HasExited) {
|
if ($FlaskProcess -and !$FlaskProcess.HasExited) {
|
||||||
$FlaskProcess.Kill()
|
$FlaskProcess.Kill()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user