File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,9 @@ nssm set buildkite-agent AppStderr C:\buildkite-agent\buildkite-agent.log
168
168
If ($lastexitcode -ne 0 ) { Exit $lastexitcode }
169
169
nssm set buildkite- agent AppEnvironmentExtra :HOME= C:\buildkite- agent
170
170
If ($lastexitcode -ne 0 ) { Exit $lastexitcode }
171
- nssm set buildkite- agent AppExit Default Exit
171
+ nssm set buildkite- agent AppExit Default Restart
172
+ If ($lastexitcode -ne 0 ) { Exit $lastexitcode }
173
+ nssm set buildkite- agent AppRestartDelay 10000
172
174
If ($lastexitcode -ne 0 ) { Exit $lastexitcode }
173
175
nssm set buildkite- agent AppEvents Exit / Post " powershell C:\buildkite-agent\bin\terminate-instance.ps1"
174
176
If ($lastexitcode -ne 0 ) { Exit $lastexitcode }
Original file line number Diff line number Diff line change 1
- # Stop script execution when a non-terminating error occurs
2
- $ErrorActionPreference = " Stop"
3
-
4
1
$InstanceId = (Invoke-WebRequest - UseBasicParsing http:// 169.254 .169.254 / latest/ meta- data/ instance- id).content
5
2
$Region = (Invoke-WebRequest - UseBasicParsing http:// 169.254 .169.254 / latest/ meta- data/ placement/ availability- zone).content -replace " .$"
6
3
7
- aws autoscaling terminate- instance- in- auto- scaling- group -- region " $Region " -- instance- id " $InstanceId " " --should-decrement-desired-capacity"
4
+ Write-Output " terminate-instance: requesting instance termination..."
5
+ aws autoscaling terminate- instance- in- auto- scaling- group -- region " $Region " -- instance- id " $InstanceId " " --should-decrement-desired-capacity" 2> $null
8
6
9
- Stop-Computer $env: computername - Force
7
+ if ($lastexitcode -eq 0 ) { # If autoscaling request was successful, we will terminate
8
+ Write-Output " terminate-instance: disabling buildkite-agent service"
9
+ nssm stop buildkite- agent
10
+ }
11
+ else {
12
+ Write-Output " terminate-instance: ASG could not decrement (we're already at minSize)"
13
+ }
You can’t perform that action at this time.
0 commit comments