|
- # aspblogbrainordure-setup.ps1
- # One-time setup: creates IIS site, app pool, and CI/CD scheduled task for ASPBlogBrainOrdure test site
-
- $SITENAME = "aspblogbrainordure-test"
- $APPPOOL = "aspblogbrainordure-test"
- $WEBROOT = "C:\inetpub\wwwroot\aspblogbrainordure-test"
- $PORT = 8960
- $SCRIPTS = "C:\Scripts"
-
- Import-Module WebAdministration
-
- Write-Host "=== ASPBlogBrainOrdure Test Site Setup ==="
-
- # Create directories
- New-Item -ItemType Directory -Force -Path $WEBROOT | Out-Null
- New-Item -ItemType Directory -Force -Path $SCRIPTS | Out-Null
- Write-Host "Directories created."
-
- # Create app pool (32-bit required for ACE OLEDB)
- if (-not (Get-WebConfiguration "system.applicationHost/applicationPools/add[@name='$APPPOOL']")) {
- New-WebAppPool -Name $APPPOOL
- Write-Host "App pool $APPPOOL created."
- } else {
- Write-Host "App pool $APPPOOL already exists."
- }
- Set-ItemProperty "IIS:\AppPools\$APPPOOL" managedRuntimeVersion "v4.0"
- Set-ItemProperty "IIS:\AppPools\$APPPOOL" enable32BitAppOnWin64 $true
- Set-ItemProperty "IIS:\AppPools\$APPPOOL" startMode "AlwaysRunning"
- Write-Host "App pool configured (32-bit, v4.0)."
-
- # Create IIS site
- $existingSite = Get-Website -Name $SITENAME -ErrorAction SilentlyContinue
- if ($existingSite) {
- Write-Host "Site $SITENAME already exists - skipping creation."
- } else {
- New-Website -Name $SITENAME -PhysicalPath $WEBROOT -Port $PORT -ApplicationPool $APPPOOL
- Write-Host "IIS site $SITENAME created on port $PORT."
- }
-
- # Enable Parent Paths for ASP
- Set-WebConfigurationProperty -Filter "system.webServer/asp" -PSPath "IIS:\Sites\$SITENAME" -Name "enableParentPaths" -Value $true
- Write-Host "Parent paths enabled."
-
- # Create a placeholder Default.asp so the site doesn't 500 before first deploy
- $placeholder = "<%Response.Write ""ASPBlogBrainOrdure - Awaiting first deploy..."" %>"
- [System.IO.File]::WriteAllText("$WEBROOT\Default.asp", $placeholder)
- Write-Host "Placeholder Default.asp created."
-
- # Copy the deploy script to Scripts folder
- $deployScriptSrc = Split-Path $PSScriptRoot -Parent
- $deployScript = "$SCRIPTS\deploy-aspblogbrainordure-test.ps1"
-
- # Write the deploy script inline (will be updated by CI/CD from repo)
- # For now, copy from the repo path passed in or the current location
- if (Test-Path "$PSScriptRoot\deploy-aspblogbrainordure-test.ps1") {
- Copy-Item "$PSScriptRoot\deploy-aspblogbrainordure-test.ps1" $deployScript -Force
- Write-Host "Deploy script copied to $deployScript."
- }
-
- # Register scheduled task (runs every 5 minutes)
- $taskName = "ASPBlogBrainOrdure-Test-Deploy"
- $existing = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
- if ($existing) {
- Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
- Write-Host "Removed existing scheduled task."
- }
- $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NonInteractive -ExecutionPolicy Bypass -File `"$deployScript`""
- $trigger = New-ScheduledTaskTrigger -RepetitionInterval (New-TimeSpan -Minutes 5) -Once -At (Get-Date)
- $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 10) -MultipleInstances IgnoreNew
- Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest -User "SYSTEM" | Out-Null
- Write-Host "Scheduled task '$taskName' created (every 5 min)."
-
- # Run first deploy immediately
- Write-Host "Running first deploy..."
- & powershell.exe -NonInteractive -ExecutionPolicy Bypass -File $deployScript
- Write-Host "First deploy complete."
-
- Write-Host ""
- Write-Host "=== Setup complete ==="
- Write-Host "Test site: http://win-rfvbip1nu8m:$PORT"
- Write-Host "Webroot: $WEBROOT"
- Write-Host "App Pool: $APPPOOL (32-bit, v4.0)"
- Write-Host "CI/CD: $taskName (every 5 min)"
|