ci: keep WSL agent online for pipelines [CI]
This commit is contained in:
1 parent
1975253beb
commit
9919de53d3
3 files changed
+25
-2
No files matched your search
@@ -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
|
||||
@@ -1,7 +1,7 @@
|
||||
[Unit]
|
||||
Description=Woodpecker agent in rootless Podman (WSL local backend)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
After=network-online.target user@1000.service
|
||||
Wants=network-online.target user@1000.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
@@ -10,6 +10,7 @@ Group=justme
|
||||
WorkingDirectory=/home/justme/woodpecker
|
||||
Environment=HOME=/home/justme
|
||||
Environment=XDG_RUNTIME_DIR=/run/user/1000
|
||||
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
|
||||
ExecStartPre=-/usr/bin/podman rm --force woodpecker-agent-podman
|
||||
ExecStart=/usr/bin/podman run --rm --pull=never --name woodpecker-agent-podman --security-opt=seccomp=unconfined --cap-add=SYS_ADMIN --device=/dev/fuse --network=host --volume=/home/justme:/home/justme:rw,rslave --env-file=/home/justme/woodpecker/agent-podman.env localhost/moshiro-woodpecker-agent:ci
|
||||
ExecStop=-/usr/bin/podman stop --time 30 woodpecker-agent-podman
|
||||
|
||||
Reference in new issue
Block a user