boot-start.template.ps1 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <#
  2. .SYNOPSIS
  3. TEMPLATE: Boot-time launcher for Process Compose with explicit PATH setup.
  4. .DESCRIPTION
  5. Copy to <your-stack>/scripts/boot-start.ps1 and adapt the $pathParts array
  6. for your machine. Invoked by Task Scheduler at boot (see
  7. boot-task-install.template.ps1).
  8. Why a wrapper: Task Scheduler runs with a minimal PATH, so services that
  9. rely on python/uv/openssl/cloudflared would otherwise fail at boot.
  10. #>
  11. [CmdletBinding()]
  12. param()
  13. $ErrorActionPreference = 'Continue'
  14. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  15. $root = (Resolve-Path (Join-Path $scriptDir '..')).Path
  16. $pcExe = Join-Path $root 'bin\process-compose.exe'
  17. $pcYaml = Join-Path $root 'process-compose.yaml'
  18. $logFile = Join-Path $root 'logs\process-compose.log'
  19. $bootLog = Join-Path $root 'logs\boot-start.log'
  20. New-Item -ItemType Directory -Force -Path (Join-Path $root 'logs') | Out-Null
  21. "[$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')] boot-start invoked. User: $env:USERNAME" | Out-File -FilePath $bootLog -Append
  22. # ─── CUSTOMIZE PATH HERE ───────────────────────────────────────────────────
  23. # Add directories for binaries that your managed services need (python, uv,
  24. # git tools, cloudflared, language SDKs, etc.). Test by running this script
  25. # manually before relying on it at boot.
  26. $pathParts = @(
  27. "$root\bin" # PC + committed binaries
  28. "C:\Program Files\Git\usr\bin" # openssl, bash, coreutils
  29. "C:\Program Files\Git\bin" # git
  30. "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python313" # python, pythonw
  31. "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python313\Scripts" # uv, pip, etc.
  32. # Add more as needed:
  33. # "C:\Program Files (x86)\cloudflared"
  34. # "C:\Program Files\nodejs"
  35. "C:\Windows\System32"
  36. "C:\Windows"
  37. $env:PATH
  38. )
  39. $env:PATH = ($pathParts -join ';')
  40. "[$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')] PATH set, $($pathParts.Count) entries" | Out-File -FilePath $bootLog -Append
  41. # ─── OPTIONAL: load secrets from gitignored .env ──────────────────────────
  42. $envFile = Join-Path $root '.env'
  43. if (Test-Path $envFile) {
  44. "[$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')] Loading .env" | Out-File -FilePath $bootLog -Append
  45. Get-Content $envFile | ForEach-Object {
  46. if ($_ -match '^\s*([A-Z_]+)\s*=\s*(.+?)\s*$') {
  47. [Environment]::SetEnvironmentVariable($matches[1], $matches[2], 'Process')
  48. }
  49. }
  50. }
  51. # ─── OPTIONAL: explicitly UNSET env vars that conflict with services ──────
  52. # Example: if a daemon enforces OAuth-only and refuses to start with stale API keys
  53. # [Environment]::SetEnvironmentVariable('SOME_API_KEY', $null, 'Process')
  54. "[$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')] Starting process-compose..." | Out-File -FilePath $bootLog -Append
  55. # ─── LAUNCH ───────────────────────────────────────────────────────────────
  56. # -p 8888 API port (avoid common collisions on 8080; pick what's free)
  57. # -t=false no TUI (headless background daemon mode)
  58. # -L PC's own log file
  59. & $pcExe -p 8888 -t=false -L $logFile up -f $pcYaml
  60. "[$(Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK')] process-compose exited code $LASTEXITCODE" | Out-File -FilePath $bootLog -Append