@@ -291,7 +291,7 @@ jobs:
291291 Write-Host "WARNING: wolfssh.exe not found (SSH client test will be skipped)"
292292 }
293293
294- - name : Start wolfSSHd in background
294+ - name : Start wolfSSHd as Windows service
295295 working-directory : ${{ github.workspace }}\wolfssh
296296 shell : pwsh
297297 run : |
@@ -301,22 +301,69 @@ jobs:
301301 exit 1
302302 }
303303
304- # Start wolfsshd in background
305- $sshdProcess = Start-Process -FilePath $sshdPath `
306- -ArgumentList "-D", "-f", "sshd_config_test", "-p", "${{env.TEST_PORT}}" `
307- -PassThru -NoNewWindow
304+ # Get absolute path for service
305+ $sshdPathFull = (Resolve-Path $sshdPath).Path
306+ $configPathFull = (Resolve-Path "sshd_config_test").Path
308307
309- Write-Host "Started wolfSSHd with PID: $($sshdProcess.Id)"
310- Add-Content -Path $env:GITHUB_ENV -Value "SSHD_PID=$($sshdProcess.Id) "
308+ # Service name
309+ $serviceName = "wolfsshd "
311310
312- # Wait a bit for server to start
311+ # Remove service if it already exists
312+ $existingService = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
313+ if ($existingService) {
314+ Write-Host "Removing existing $serviceName service"
315+ if ($existingService.Status -eq 'Running') {
316+ Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue
317+ Start-Sleep -Seconds 2
318+ }
319+ sc.exe delete $serviceName | Out-Null
320+ Start-Sleep -Seconds 2
321+ }
322+
323+ # Create the service with proper binpath
324+ # binpath format: "path\to\exe" -f "config" -p port
325+ $binPath = "`"$sshdPathFull`" -f `"$configPathFull`" -p ${{env.TEST_PORT}}"
326+ Write-Host "Creating service with binpath: $binPath"
327+
328+ $createResult = sc.exe create $serviceName binPath= $binPath
329+ if ($LASTEXITCODE -ne 0) {
330+ Write-Host "ERROR: Failed to create service"
331+ Write-Host $createResult
332+ exit 1
333+ }
334+ Write-Host "Service created: $createResult"
335+
336+ # Start the service
337+ Write-Host "Starting $serviceName service"
338+ $startResult = sc.exe start $serviceName
339+ if ($LASTEXITCODE -ne 0) {
340+ Write-Host "ERROR: Failed to start service"
341+ Write-Host $startResult
342+ # Try to get service status for debugging
343+ sc.exe query $serviceName
344+ exit 1
345+ }
346+ Write-Host "Service started: $startResult"
347+
348+ # Wait a bit for service to start
313349 Start-Sleep -Seconds 3
314350
315- # Check if process is still running
316- if (-not (Get-Process -Id $sshdProcess.Id -ErrorAction SilentlyContinue)) {
317- Write-Host "ERROR: wolfSSHd process exited immediately"
351+ # Check service status
352+ $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
353+ if (-not $service) {
354+ Write-Host "ERROR: Service $serviceName not found after creation"
355+ exit 1
356+ }
357+
358+ if ($service.Status -ne 'Running') {
359+ Write-Host "ERROR: Service is not running. Status: $($service.Status)"
360+ # Get more details
361+ sc.exe query $serviceName
318362 exit 1
319363 }
364+
365+ Write-Host "wolfSSHd service is running (Status: $($service.Status))"
366+ Add-Content -Path $env:GITHUB_ENV -Value "SSHD_SERVICE_NAME=$serviceName"
320367
321368 - name : Test SFTP connection
322369 working-directory : ${{ github.workspace }}\wolfssh
@@ -486,13 +533,23 @@ jobs:
486533 working-directory : ${{ github.workspace }}\wolfssh
487534 shell : pwsh
488535 run : |
489- # Stop wolfSSHd
490- if ($env:SSHD_PID) {
491- $pid = [int]$env:SSHD_PID
492- if (Get-Process -Id $pid -ErrorAction SilentlyContinue) {
493- Stop-Process -Id $pid -Force
494- Write-Host "Stopped wolfSSHd process $pid"
536+ # Stop and remove wolfSSHd service
537+ $serviceName = $env:SSHD_SERVICE_NAME
538+ if ([string]::IsNullOrEmpty($serviceName)) {
539+ $serviceName = "wolfsshd"
540+ }
541+
542+ $service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
543+ if ($service) {
544+ if ($service.Status -eq 'Running') {
545+ Write-Host "Stopping $serviceName service"
546+ Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue
547+ Start-Sleep -Seconds 2
495548 }
549+
550+ Write-Host "Deleting $serviceName service"
551+ sc.exe delete $serviceName | Out-Null
552+ Start-Sleep -Seconds 1
496553 }
497554
498555 # Remove test certificates from store
0 commit comments