|
66 | 66 | } |
67 | 67 | Write-Output "Extracting new containerd binaries" |
68 | 68 | tar.exe -zxvf c:/k/containerd.tar.gz -C "c:/Program Files/containerd" --strip-components 1 |
69 | | -
|
70 | | - Start-Service containerd |
| 69 | + # Check if kube-log-runner.exe exists |
| 70 | + if (Test-Path $kubeloggerPath) { |
| 71 | + Write-Output "Recreating containerd service with kube-log-runner..." |
| 72 | + $logPath = "\var\log\containerd" |
| 73 | + # Check if directory exists |
| 74 | + if (-Not (Test-Path -Path $logPath -PathType Container)) { |
| 75 | + Write-Host "Creating log directory: $logPath" |
| 76 | + New-Item -ItemType Directory -Path $logPath -Force | Out-Null |
| 77 | + } else { |
| 78 | + Write-Host "Log directory already exists: $logPath" |
| 79 | + } |
| 80 | + $ContainerdCommandLine = 'c:\k\kube-log-runner.exe --log-file=/var/log/containerd/containerd.log "c:\Program Files\containerd\containerd.exe" --register-service' |
| 81 | + Write-Output "Containerd command line: $ContainerdCommandLine" |
| 82 | + # Stop and delete the existing containerd service |
| 83 | + Stop-Service -Name 'containerd' -Force -ErrorAction SilentlyContinue |
| 84 | + $null = sc.exe delete containerd |
| 85 | + # Wait for service to be fully deleted |
| 86 | + $serviceCreated = $false |
| 87 | + for ($i = 0; $i -lt 20; $i++) { |
| 88 | + $service = Get-Service -Name containerd -ErrorAction SilentlyContinue |
| 89 | + if ($null -eq $service) { |
| 90 | + Write-Host "containerd service deleted successfully, recreating with kubelogger" |
| 91 | + cmd.exe /c $ContainerdCommandLine |
| 92 | + Start-Service Containerd |
| 93 | + Write-Output "Successfully started containerd service with kubelogger" |
| 94 | + $serviceCreated = $true |
| 95 | + break |
| 96 | + } |
| 97 | + else { |
| 98 | + Write-Host "Waiting for containerd service to be fully deleted... (attempt $($i + 1)/20)" |
| 99 | + } |
| 100 | + Start-Sleep -Seconds 1 |
| 101 | + } |
| 102 | + if (-not $serviceCreated) { |
| 103 | + Write-Error "Failed to delete containerd service after 20 attempts" |
| 104 | + } |
| 105 | + } else { |
| 106 | + Write-Output "Starting containerd service without kube-log-runner..." |
| 107 | + Start-Service containerd |
| 108 | + } |
71 | 109 | } |
72 | 110 | containerd.exe --version |
73 | 111 | containerd-shim-runhcs-v1.exe --version |
|
0 commit comments