Skip to content

Commit 4ecfc29

Browse files
author
James Healy
authored
Merge pull request #746 from buildkite/chloeruka/windows-quickfix
Configure Windows service exit like the unix service
2 parents 68fec04 + 2fa759e commit 4ecfc29

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packer/windows/conf/bin/bk-install-elastic-stack.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ nssm set buildkite-agent AppStderr C:\buildkite-agent\buildkite-agent.log
168168
If ($lastexitcode -ne 0) { Exit $lastexitcode }
169169
nssm set buildkite-agent AppEnvironmentExtra :HOME=C:\buildkite-agent
170170
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
172174
If ($lastexitcode -ne 0) { Exit $lastexitcode }
173175
nssm set buildkite-agent AppEvents Exit/Post "powershell C:\buildkite-agent\bin\terminate-instance.ps1"
174176
If ($lastexitcode -ne 0) { Exit $lastexitcode }
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Stop script execution when a non-terminating error occurs
2-
$ErrorActionPreference = "Stop"
3-
41
$InstanceId = (Invoke-WebRequest -UseBasicParsing http://169.254.169.254/latest/meta-data/instance-id).content
52
$Region = (Invoke-WebRequest -UseBasicParsing http://169.254.169.254/latest/meta-data/placement/availability-zone).content -replace ".$"
63

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
86

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+
}

0 commit comments

Comments
 (0)