# Service Management Scripts Simple PowerShell scripts to manage the Geutebruck API services. ## Quick Start ### Start Both Services ```powershell .\start-services.ps1 ``` ### Stop Both Services ```powershell .\stop-services.ps1 ``` ### Restart Both Services ```powershell .\restart-services.ps1 ``` ### Check Status ```powershell .\status-services.ps1 ``` --- ## What Each Script Does ### start-services.ps1 - Starts SDK Bridge (GeViScopeBridge.exe) - Starts Python API (uvicorn) - Checks if already running (won't start duplicates) - Runs both in background - Shows PIDs and URLs ### stop-services.ps1 - Stops SDK Bridge - Stops Python API - Safe to run even if not running ### restart-services.ps1 - Stops both services - Waits 2 seconds - Starts both services ### status-services.ps1 - Shows running status - Shows PIDs - Shows URLs - Tests API health endpoint --- ## Running as Windows Services (Optional) If you want the services to start automatically on boot, use NSSM (Non-Sucking Service Manager): ### 1. Install NSSM ```powershell # Using Chocolatey choco install nssm # Or download from: https://nssm.cc/download ``` ### 2. Install SDK Bridge Service ```powershell nssm install GeutebruckSDKBridge "C:\DEV\COPILOT\geutebruck-api\src\sdk-bridge\GeViScopeBridge\bin\Release\net8.0\GeViScopeBridge.exe" nssm set GeutebruckSDKBridge AppDirectory "C:\DEV\COPILOT\geutebruck-api\src\sdk-bridge\GeViScopeBridge\bin\Release\net8.0" nssm set GeutebruckSDKBridge Description "Geutebruck SDK Bridge - gRPC server for GeViScope/GeViSoft" nssm set GeutebruckSDKBridge Start SERVICE_AUTO_START nssm start GeutebruckSDKBridge ``` ### 3. Install Python API Service ```powershell nssm install GeutebruckAPI "C:\DEV\COPILOT\geutebruck-api\.venv\Scripts\uvicorn.exe" nssm set GeutebruckAPI AppParameters "main:app --host 0.0.0.0 --port 8000" nssm set GeutebruckAPI AppDirectory "C:\DEV\COPILOT\geutebruck-api\src\api" nssm set GeutebruckAPI Description "Geutebruck REST API - FastAPI service" nssm set GeutebruckAPI Start SERVICE_AUTO_START nssm set GeutebruckAPI DependOnService GeutebruckSDKBridge nssm start GeutebruckAPI ``` ### 4. Manage Windows Services ```powershell # Start nssm start GeutebruckSDKBridge nssm start GeutebruckAPI # Stop nssm stop GeutebruckAPI nssm stop GeutebruckSDKBridge # Restart nssm restart GeutebruckSDKBridge nssm restart GeutebruckAPI # Remove nssm remove GeutebruckAPI confirm nssm remove GeutebruckSDKBridge confirm # Check status nssm status GeutebruckSDKBridge nssm status GeutebruckAPI ``` --- ## Alternative: Task Scheduler (Auto-start on Login) If you don't want full Windows services but want auto-start on login: ### Create Scheduled Task ```powershell $action = New-ScheduledTaskAction -Execute "PowerShell.exe" ` -Argument "-ExecutionPolicy Bypass -File C:\DEV\COPILOT\geutebruck-api\start-services.ps1" ` -WorkingDirectory "C:\DEV\COPILOT\geutebruck-api" $trigger = New-ScheduledTaskTrigger -AtLogOn $principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -RunLevel Highest Register-ScheduledTask -TaskName "Geutebruck API Services" ` -Action $action ` -Trigger $trigger ` -Principal $principal ` -Description "Start Geutebruck API services on login" ``` ### Remove Scheduled Task ```powershell Unregister-ScheduledTask -TaskName "Geutebruck API Services" -Confirm:$false ``` --- ## Troubleshooting ### Services Won't Start 1. Check if ports are already in use: ```powershell netstat -ano | findstr "8000" netstat -ano | findstr "50051" ``` 2. Check GeViServer and GSCServer are running: ```powershell Get-Process -Name "GeViServer","GSCServer" ``` 3. Check logs: - SDK Bridge: `C:\DEV\COPILOT\geutebruck-api\src\sdk-bridge\GeViScopeBridge\bin\Release\net8.0\logs\` - Python API: Check console output or add logging ### Can't Stop Services ```powershell # Force kill by name Stop-Process -Name "GeViScopeBridge" -Force Stop-Process -Name "uvicorn" -Force # Or by port $process = Get-NetTCPConnection -LocalPort 8000 | Select-Object -ExpandProperty OwningProcess Stop-Process -Id $process -Force ``` ### Execution Policy Error ```powershell # Allow scripts for current user Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser # Or run with bypass PowerShell -ExecutionPolicy Bypass -File .\start-services.ps1 ``` --- ## Recommended Setup **For Development**: - Use `start-services.ps1` / `stop-services.ps1` scripts - Keep `--reload` flag for auto-reload on code changes **For Production**: - Use NSSM to create Windows services - Remove `--reload` flag from uvicorn - Configure services to auto-start - Set up service recovery options in NSSM --- ## Quick Reference | Command | Purpose | |---------|---------| | `.\start-services.ps1` | Start both services | | `.\stop-services.ps1` | Stop both services | | `.\restart-services.ps1` | Restart both services | | `.\status-services.ps1` | Check service status | | `http://localhost:8000/docs` | Swagger UI | | `http://localhost:8000/health` | Health check |