-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from zenitsu0509/main
Add PowerShell Script for Windows Backend Execution
- Loading branch information
Showing
3 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
private = dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5TjRQaUpFRXRad0dDbkNpTHlVNFBOWmZCaDRRWGNDcDdHQ3c5a0hRSUE3NEFBQkFBQUFBQUFBQUFBQUlBQUFBQVhoT1pUY2xvak01d0ZKeVVYdlVnQnlGQXlkUFhuRkdBMEY0QmdYWCtXUCtvaDMvS2tNYnJHSytXcGluQytFQWxPYm1UbVZNdU85aU53aEdJT1IveE82LzB2K2swS0MyZlFybmt5SG51aEt3YlVmMWdDSHBkN1llelU2L0JKT1puVGZFc3liNXplRlk9Cg== | ||
public = dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDY1MDM5OUIzNDQ5MTNEOTMKUldTVFBaRkVzNWtEWlRxWWJCeXhtMTV6ZXZ3OUs0SXhzQzBreVRoekl5bjdXS3hkZlZzQ3VvTkgK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# PowerShell equivalent of the bash script | ||
|
||
# Handle Ctrl+C | ||
$script:running = $true | ||
[Console]::TreatControlCAsInput = $true | ||
|
||
function Handle-CtrlC { | ||
Write-Host "Exiting..." | ||
$script:running = $false | ||
exit 0 | ||
} | ||
|
||
# Start a job to check for Ctrl+C | ||
Start-Job -ScriptBlock { | ||
while ($true) { | ||
if ([Console]::KeyAvailable) { | ||
$key = [Console]::ReadKey($true) | ||
if (($key.Modifiers -band [ConsoleModifiers]::Control) -and ($key.Key -eq 'C')) { | ||
Handle-CtrlC | ||
} | ||
} | ||
Start-Sleep -Milliseconds 100 | ||
} | ||
} | Out-Null | ||
|
||
if ($args[0] -eq "--test") { | ||
while ($script:running) { | ||
Write-Host "Starting Hypercorn server in test environment..." | ||
$process = Start-Process -FilePath "hypercorn" -ArgumentList "main:app --bind 0.0.0.0:8000 --log-level debug --reload --access-log -" -RedirectStandardOutput "hypercorn.log" -RedirectStandardError "hypercorn.log" -PassThru | ||
|
||
# Monitor the log file for errors | ||
Get-Content "hypercorn.log" -Wait | ForEach-Object { | ||
Write-Host $_ | ||
if ($_ -match "Syntax error") { | ||
Write-Host "Syntax error detected. Restarting server..." | ||
$process.Kill() | ||
} | ||
} | ||
|
||
Write-Host "Hypercorn server crashed in test environment. Restarting in 3 seconds..." | ||
Start-Sleep -Seconds 3 | ||
} | ||
} | ||
else { | ||
# Get the WORKERS environment variable or default to 1 | ||
$workers = if ($env:WORKERS) { $env:WORKERS } else { "1" } | ||
Write-Host "WORKERS: $workers" | ||
hypercorn main:app --workers $workers --bind 0.0.0.0:8000 | ||
} |