Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from buildkite/lifecycled-the-second
Replace lifecycled without SNS/SQS
- Loading branch information
Showing
10 changed files
with
113 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
# This script is a daemon that monitors for the instance’s autoscaling state | ||
# group to put it into a `terminating:wait` state, and then runs a hook before | ||
# telling the autoscaling group to proceed with the termination. This allows | ||
# us to wait for all buildkite-agent jobs to complete on the instance before | ||
# termination. | ||
# | ||
# Expects /etc/terminationd/hook to be installed and executable | ||
|
||
AWS_REGION="$(/opt/aws/bin/ec2-metadata --availability-zone | cut -d " " -f 2 | head -c -2)" | ||
INSTANCE_ID="$(/opt/aws/bin/ec2-metadata --instance-id | cut -d " " -f 2)" | ||
|
||
echo "Monitoring instance state for ${INSTANCE_ID}" | ||
|
||
while true; do | ||
LIFECYCLE_STATE="$(aws --region "${AWS_REGION}" autoscaling describe-auto-scaling-instances \ | ||
--instance-ids "${INSTANCE_ID}" \ | ||
--query AutoScalingInstances[].LifecycleState --output text)" | ||
|
||
echo "Lifecycle state is ${LIFECYCLE_STATE}" | ||
|
||
if [[ "${LIFECYCLE_STATE}" == "Terminating:Wait" ]]; then | ||
break | ||
else | ||
sleep 15 # seconds | ||
fi | ||
done | ||
|
||
echo "Running terminationd hook" | ||
|
||
/etc/terminationd/hook || true | ||
|
||
echo "Fetching autoscaling group name" | ||
|
||
AUTO_SCALING_GROUP_NAME="$(aws --region "${AWS_REGION}" ec2 describe-tags \ | ||
--filters "Name=resource-id,Values=${INSTANCE_ID}" \ | ||
"Name=key,Values=aws:autoscaling:groupName" \ | ||
--query "Tags[].Value" --output text)" | ||
|
||
echo "Fetching lifecycle hook name" | ||
|
||
LIFECYCLE_HOOK_NAME="$(aws --region "${AWS_REGION}" autoscaling describe-lifecycle-hooks \ | ||
--auto-scaling-group-name "${AUTO_SCALING_GROUP_NAME}" \ | ||
--query "LifecycleHooks[].LifecycleHookName" --output text)" | ||
|
||
echo "Completing lifecycle action for ${AUTO_SCALING_GROUP_NAME} ${LIFECYCLE_HOOK_NAME}" | ||
|
||
aws --region "${AWS_REGION}" autoscaling complete-lifecycle-action \ | ||
--auto-scaling-group-name "${AUTO_SCALING_GROUP_NAME}" \ | ||
--lifecycle-hook-name "${LIFECYCLE_HOOK_NAME}" \ | ||
--instance-id "${INSTANCE_ID}" \ | ||
--lifecycle-action-result CONTINUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
start on runlevel [2345] | ||
|
||
stop on runlevel [!2345] | ||
|
||
respawn | ||
|
||
script | ||
set -a | ||
mkfifo /tmp/terminationd-log-fifo | ||
( logger -t terminationd </tmp/terminationd-log-fifo & ) | ||
exec >/tmp/terminationd-log-fifo | ||
exec 2>&1 | ||
rm /tmp/terminationd-log-fifo | ||
exec /usr/bin/terminationd | ||
end script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
sudo mkdir /etc/terminationd | ||
sudo cp /tmp/conf/terminationd/bin/* /usr/bin | ||
sudo cp /tmp/conf/terminationd/upstart/* /etc/init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters