From 914ab0107ea770cd30ad306466de3e74f039c45c Mon Sep 17 00:00:00 2001 From: Marius Mutu Date: Wed, 12 Nov 2025 02:46:02 +0200 Subject: [PATCH] Fix Backend service PYTHONPATH for shared module imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../windows/scripts/Fix-BackendPythonPath.ps1 | 31 +++++++++++++++++++ .../windows/scripts/ROA2WEB-Console.ps1 | 5 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 deployment/windows/scripts/Fix-BackendPythonPath.ps1 diff --git a/deployment/windows/scripts/Fix-BackendPythonPath.ps1 b/deployment/windows/scripts/Fix-BackendPythonPath.ps1 new file mode 100644 index 0000000..b4cd46b --- /dev/null +++ b/deployment/windows/scripts/Fix-BackendPythonPath.ps1 @@ -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 diff --git a/deployment/windows/scripts/ROA2WEB-Console.ps1 b/deployment/windows/scripts/ROA2WEB-Console.ps1 index db7b113..a1e018e 100644 --- a/deployment/windows/scripts/ROA2WEB-Console.ps1 +++ b/deployment/windows/scripts/ROA2WEB-Console.ps1 @@ -624,7 +624,10 @@ function Install-BackendFirstTime { & nssm set $Config.BackendServiceName Description $Config.BackendServiceDescription & nssm set $Config.BackendServiceName Start SERVICE_AUTO_START & 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 $stdoutLog = Join-Path $Config.LogsPath "backend-stdout.log"