ci: keep WSL agent online for pipelines [CI]
ci/woodpecker/push/web-build Pipeline was successful
ci/woodpecker/push/verify Pipeline was successful
ci/woodpecker/push/dev-image Pipeline was canceled

This commit is contained in:
justme committed 2026-10-10 05:48:48 -07:00
1 parent 1975253beb
commit 9919de53d3
3 files changed
+25 -2

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
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