Files
MoShiro/ci/start-wsl-runner.ps1
T
justme 9919de53d3
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was canceled
ci: keep WSL agent online for pipelines [CI]
2026-10-10 05:48:48 -07:00

21 lines
1.5 KiB
PowerShell

param(
[string]$Distribution = 'Debian',
[string]$LinuxUser = 'justme'
)
$ErrorActionPreference = 'Stop'
# systemd services alone do not keep a WSL distribution running.
# Run a foreground Linux process in a hidden Windows task at user logon.
if ($Distribution -notmatch '^[a-zA-Z0-9_.-]+$' -or $LinuxUser -notmatch '^[a-zA-Z0-9_.-]+$') {
throw 'Distribution and user names must contain only letters, digits, _, . or -.'
}
$userName = [Security.Principal.WindowsIdentity]::GetCurrent().Name
$taskName = "MoShiro WSL runner ($Distribution)"
$command = "& '$env:SystemRoot\System32\wsl.exe' --distribution $Distribution --user $LinuxUser --exec /bin/sleep infinity"
$action = New-ScheduledTaskAction -Execute "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument "-NoProfile -WindowStyle Hidden -Command `"$command`""
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $userName
$principal = New-ScheduledTaskPrincipal -UserId $userName -LogonType Interactive -RunLevel Limited
$settings = New-ScheduledTaskSettingsSet -Hidden -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Description 'Keep Debian WSL running for the systemd Woodpecker CI agent.' -Force | Out-Null
Start-ScheduledTask -TaskName $taskName
Get-ScheduledTask -TaskName $taskName | Select-Object TaskName, State