Run Vili through a Raven scheduled task
This commit is contained in:
parent
ca6a172cdd
commit
de2ad53e48
3 changed files with 47 additions and 1 deletions
16
scripts/install-vili-task.ps1
Normal file
16
scripts/install-vili-task.ps1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
param(
|
||||
[string]$TaskName = "GameCult\Vili",
|
||||
[int]$Port = 8824,
|
||||
[string]$HostName = "0.0.0.0",
|
||||
[string]$StateRoot = "E:\Projects\Vili\.vili"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$RunScript = Join-Path $PSScriptRoot "run-vili-daemon.ps1"
|
||||
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$RunScript`" -Port $Port -HostName `"$HostName`" -StateRoot `"$StateRoot`""
|
||||
$Trigger = New-ScheduledTaskTrigger -AtStartup
|
||||
$Principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType S4U -RunLevel Highest
|
||||
$Settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew
|
||||
|
||||
Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings -Force | Out-Null
|
||||
Write-Host "Installed scheduled task $TaskName"
|
||||
|
|
@ -6,6 +6,7 @@ param(
|
|||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$PidPath = Join-Path $StateRoot "vili-daemon.pid"
|
||||
$TaskName = "GameCult\Vili"
|
||||
|
||||
if (Test-Path $PidPath) {
|
||||
$existingPid = (Get-Content $PidPath -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
|
|
@ -18,4 +19,16 @@ if (Test-Path $PidPath) {
|
|||
}
|
||||
}
|
||||
|
||||
& (Join-Path $PSScriptRoot "start-vili-daemon.ps1") -Port $Port -HostName $HostName -StateRoot $StateRoot
|
||||
if (Get-ScheduledTask -TaskName "Vili" -TaskPath "\GameCult\" -ErrorAction SilentlyContinue) {
|
||||
Stop-ScheduledTask -TaskName "Vili" -TaskPath "\GameCult\" -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 1
|
||||
Start-ScheduledTask -TaskName "Vili" -TaskPath "\GameCult\"
|
||||
Start-Sleep -Seconds 3
|
||||
node (Join-Path (Split-Path -Parent $PSScriptRoot) "scripts\vili-daemon.mjs") --health --host 127.0.0.1 --port $Port --state-root $StateRoot
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Vili scheduled task started but health check failed."
|
||||
}
|
||||
Write-Host "Vili restarted through scheduled task $TaskName"
|
||||
} else {
|
||||
& (Join-Path $PSScriptRoot "start-vili-daemon.ps1") -Port $Port -HostName $HostName -StateRoot $StateRoot
|
||||
}
|
||||
|
|
|
|||
17
scripts/run-vili-daemon.ps1
Normal file
17
scripts/run-vili-daemon.ps1
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
param(
|
||||
[int]$Port = 8824,
|
||||
[string]$HostName = "0.0.0.0",
|
||||
[string]$StateRoot = "E:\Projects\Vili\.vili"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path -Parent $PSScriptRoot
|
||||
$Node = (Get-Command node -ErrorAction Stop).Source
|
||||
$LogDir = Join-Path $StateRoot "logs"
|
||||
$OutLog = Join-Path $LogDir "vili-daemon.out.log"
|
||||
$ErrLog = Join-Path $LogDir "vili-daemon.err.log"
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $LogDir | Out-Null
|
||||
|
||||
Set-Location $Root
|
||||
& $Node (Join-Path $Root "scripts\vili-daemon.mjs") --host $HostName --port $Port --state-root $StateRoot 1>> $OutLog 2>> $ErrLog
|
||||
Loading…
Reference in a new issue