Repository navigation
Expand file tree
/
Copy pathrun_api_detached.ps1
More file actions
51 lines (44 loc) · 1.75 KB
/
Copy pathrun_api_detached.ps1
File metadata and controls
51 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param(
# Bind to all interfaces so other machines (e.g. ComfyGallery on the NAS)
# can reach the API. Pass -BindAddress 127.0.0.1 to restrict to loopback.
[string]$BindAddress = "0.0.0.0",
[int]$Port = 8000
)
$ProjectDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
$PythonExecutable = "F:\Anaconda3\envs\sharp\python.exe"
$OutputDirectory = Join-Path $ProjectDirectory "output"
$LogDirectory = Join-Path $OutputDirectory "logs"
$PidPath = Join-Path $OutputDirectory "api.pid"
if (-not (Test-Path -LiteralPath $PythonExecutable)) {
throw "Conda Python was not found at $PythonExecutable"
}
if (Test-Path -LiteralPath $PidPath) {
$ExistingPid = Get-Content -LiteralPath $PidPath -ErrorAction SilentlyContinue
if ($ExistingPid -and (Get-Process -Id $ExistingPid -ErrorAction SilentlyContinue)) {
throw "The API already appears to be running as PID $ExistingPid"
}
}
New-Item -ItemType Directory -Path $LogDirectory -Force | Out-Null
$Timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$StandardOutput = Join-Path $LogDirectory "api-$Timestamp.log"
$StandardError = Join-Path $LogDirectory "api-$Timestamp.error.log"
$Arguments = @(
"-u",
"api_service.py",
"--host", $BindAddress,
"--port", $Port,
"--workers", "1",
"--log-level", "INFO"
)
$ApiProcess = Start-Process `
-FilePath $PythonExecutable `
-ArgumentList $Arguments `
-WorkingDirectory $ProjectDirectory `
-WindowStyle Hidden `
-RedirectStandardOutput $StandardOutput `
-RedirectStandardError $StandardError `
-PassThru
$ApiProcess.Id | Set-Content -LiteralPath $PidPath
Write-Output "Spatial API started as PID $($ApiProcess.Id)"
Write-Output "Manager: http://127.0.0.1:$Port/batch-manager"
Write-Output "Logs: $StandardOutput"