Fix Backend service PYTHONPATH for shared module imports
Fixed critical runtime error where backend service couldn't import shared modules (ModuleNotFoundError: No module named 'database'). Changes: - Updated Install-BackendFirstTime: Set PYTHONPATH to shared directory instead of parent directory - Added Fix-BackendPythonPath.ps1: Quick fix script for existing installations The backend imports 'from database.oracle_pool' which requires the database module to be in PYTHONPATH. Previously PYTHONPATH pointed to C:\inetpub\wwwroot\roa2web but the database module is located at C:\inetpub\wwwroot\roa2web\shared\database. Now PYTHONPATH correctly points to the shared directory. For existing installations, run Fix-BackendPythonPath.ps1 as Administrator to update the service configuration without reinstalling. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
31
deployment/windows/scripts/Fix-BackendPythonPath.ps1
Normal file
31
deployment/windows/scripts/Fix-BackendPythonPath.ps1
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Quick fix script to update Backend service PYTHONPATH
|
||||||
|
# Run this as Administrator to fix the ModuleNotFoundError
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$InstallPath = "C:\inetpub\wwwroot\roa2web",
|
||||||
|
[string]$ServiceName = "ROA2WEB-Backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Fixing Backend service PYTHONPATH..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Stop service
|
||||||
|
Write-Host "Stopping service..." -ForegroundColor Yellow
|
||||||
|
& nssm stop $ServiceName
|
||||||
|
Start-Sleep -Seconds 3
|
||||||
|
|
||||||
|
# Update PYTHONPATH to shared directory
|
||||||
|
$sharedPath = Join-Path $InstallPath "shared"
|
||||||
|
Write-Host "Setting PYTHONPATH to: $sharedPath" -ForegroundColor Yellow
|
||||||
|
& nssm set $ServiceName AppEnvironmentExtra "PYTHONPATH=$sharedPath"
|
||||||
|
|
||||||
|
# Start service
|
||||||
|
Write-Host "Starting service..." -ForegroundColor Yellow
|
||||||
|
& nssm start $ServiceName
|
||||||
|
Start-Sleep -Seconds 3
|
||||||
|
|
||||||
|
# Check status
|
||||||
|
Write-Host "`nChecking service status..." -ForegroundColor Cyan
|
||||||
|
& nssm status $ServiceName
|
||||||
|
|
||||||
|
Write-Host "`nDone! Check logs at: $InstallPath\logs\backend-stderr.log" -ForegroundColor Green
|
||||||
|
Write-Host "If errors persist, check the log file for details." -ForegroundColor Yellow
|
||||||
@@ -624,7 +624,10 @@ function Install-BackendFirstTime {
|
|||||||
& nssm set $Config.BackendServiceName Description $Config.BackendServiceDescription
|
& nssm set $Config.BackendServiceName Description $Config.BackendServiceDescription
|
||||||
& nssm set $Config.BackendServiceName Start SERVICE_AUTO_START
|
& nssm set $Config.BackendServiceName Start SERVICE_AUTO_START
|
||||||
& nssm set $Config.BackendServiceName AppDirectory $Config.BackendPath
|
& nssm set $Config.BackendServiceName AppDirectory $Config.BackendPath
|
||||||
& nssm set $Config.BackendServiceName AppEnvironmentExtra "PYTHONPATH=$($Config.InstallPath)"
|
|
||||||
|
# Set PYTHONPATH to shared directory for module imports
|
||||||
|
$sharedPath = Join-Path $Config.InstallPath "shared"
|
||||||
|
& nssm set $Config.BackendServiceName AppEnvironmentExtra "PYTHONPATH=$sharedPath"
|
||||||
|
|
||||||
# Set logging
|
# Set logging
|
||||||
$stdoutLog = Join-Path $Config.LogsPath "backend-stdout.log"
|
$stdoutLog = Join-Path $Config.LogsPath "backend-stdout.log"
|
||||||
|
|||||||
Reference in New Issue
Block a user