param([ValidateSet('start','stop','status')][string]$Action='status') $ErrorActionPreference='Stop' $budgetProject=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) if($budgetProject -ne 'C:\laragon\www\sgf-tempo'){throw 'Unexpected project path.'} $budgetRecord='C:\laragon\data\sgf-tempo\run\budget-demo.json' $budgetPhp='C:\laragon\tools\sgf-tempo\php-8.4.27\php.exe' if($Action -eq 'status') { Get-NetTCPConnection -LocalPort 8003 -State Listen -ErrorAction SilentlyContinue | Select-Object LocalAddress,LocalPort,OwningProcess; exit } if($Action -eq 'stop') { if(Test-Path -LiteralPath $budgetRecord){ $budgetProcessRecord=Get-Content -Raw -LiteralPath $budgetRecord | ConvertFrom-Json $budgetProcess=Get-Process -Id $budgetProcessRecord.pid -ErrorAction SilentlyContinue if($budgetProcess){if($budgetProcess.Path -ne $budgetPhp -or $budgetProcess.StartTime.ToUniversalTime().ToString('o') -ne $budgetProcessRecord.started){throw 'Process identity mismatch.'}; Stop-Process -Id $budgetProcess.Id} Remove-Item -LiteralPath $budgetRecord } Write-Output 'Budget server stopped. Demonstration data, role and credentials retained.';exit } if(Get-NetTCPConnection -LocalPort 8003 -State Listen -ErrorAction SilentlyContinue){throw 'Port 8003 occupied; no process stopped.'} if(Test-Path -LiteralPath $budgetRecord){throw 'Budget server record exists. Inspect/stop the owned server first.'} $budgetSecrets='C:\laragon\data\sgf-tempo\secrets' $budgetAccount=[Security.Principal.WindowsIdentity]::GetCurrent().Name New-Item -ItemType Directory -Path $budgetSecrets -Force | Out-Null & 'C:\Users\macbook\.config\investmoz\php-8.5.11\php.exe' (Join-Path $PSScriptRoot 'budget-demo-provision.php') if($LASTEXITCODE){throw 'Budget demonstration preparation failed.'} foreach($budgetSecret in @('budget-demo.json','budget-demo-access.json')){& icacls.exe (Join-Path $budgetSecrets $budgetSecret) /inheritance:r /grant:r "${budgetAccount}:F" 'SYSTEM:F' | Out-Null} New-Item -ItemType Directory -Path (Join-Path $budgetProject 'storage\framework\budget-demo\sessions'),(Join-Path $budgetProject 'storage\framework\budget-demo\cache'),(Join-Path $budgetProject 'storage\framework\budget-demo\locks') -Force | Out-Null $budgetProcess=Start-Process -FilePath $budgetPhp -ArgumentList @('-S','127.0.0.1:8003','-t','public','scripts/budget-demo-router.php') -WorkingDirectory $budgetProject -WindowStyle Hidden -PassThru -RedirectStandardOutput 'C:\laragon\data\sgf-tempo\run\budget-demo.stdout.log' -RedirectStandardError 'C:\laragon\data\sgf-tempo\run\budget-demo.stderr.log' @{pid=$budgetProcess.Id;started=$budgetProcess.StartTime.ToUniversalTime().ToString('o');port=8003}|ConvertTo-Json|Set-Content -LiteralPath $budgetRecord -Encoding UTF8 Write-Output 'Synthetic budget demonstration: http://127.0.0.1:8003. Existing SGF demonstrations preserved.'