26 lines
1.1 KiB
PowerShell
26 lines
1.1 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[ValidateRange(1,65535)][int]$Port = 15888,
|
|
[string]$ListenAddress = '127.0.0.1',
|
|
[string]$DatabasePath = ''
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$serverRoot = $PSScriptRoot
|
|
$executable = Join-Path $serverRoot 'aiserver.exe'
|
|
if (-not (Test-Path -LiteralPath $executable)) { throw "Missing $executable" }
|
|
if (-not $DatabasePath) { $DatabasePath = Join-Path $serverRoot 'data/aiserver.db' }
|
|
$DatabasePath = [IO.Path]::GetFullPath($DatabasePath)
|
|
$dataDirectory = Split-Path -Parent $DatabasePath
|
|
$logs = Join-Path $serverRoot 'logs'
|
|
New-Item -ItemType Directory -Path $dataDirectory,$logs -Force | Out-Null
|
|
$log = Join-Path $logs ("aiserver-{0}.log" -f (Get-Date -Format yyyyMMdd))
|
|
Push-Location $serverRoot
|
|
try {
|
|
"$(Get-Date -Format o) Starting AIServer on ${ListenAddress}:$Port" | Add-Content -LiteralPath $log
|
|
& $executable --host $ListenAddress --port $Port --db $DatabasePath --daemon 2>&1 |
|
|
Tee-Object -FilePath $log -Append
|
|
$serverExit = $LASTEXITCODE
|
|
if ($serverExit -eq 0) { $serverExit = 1 } # A daemon exiting should trigger task recovery.
|
|
exit $serverExit
|
|
} finally { Pop-Location }
|