This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tfhartmann/plat 2145 drain instances when terminating (#3)
* Adding Checks and Handlers for draining ECS instances * changed args to handler * Update JSON for watches * Watch handler must be a string * Updates to handler I had the handler set to watch a service not the check - these checks are part of the $cluster service * More handler updates * Doh... watches try to run on the parent container * some updates
- Loading branch information
1 parent
71e3ab6
commit e80566e
Showing
5 changed files
with
79 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
# >>> Currently NOT USED <<<< | ||
# We probably want to replace this with something that eats json and do this in a non-horrible way | ||
# It would safe clock time to get status from the JSON input of the consul watch. | ||
|
||
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/.$//') | ||
ARN=$(curl -s http://localhost:51678/v1/metadata | jq -r .ContainerInstanceArn) | ||
ECS_CLUSTER=$(curl -s http://localhost:51678/v1/metadata | jq -r .Cluster) | ||
ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | ||
STATUS=$(aws --region $REGION autoscaling describe-auto-scaling-instances --instance-ids $ID | jq -r '.AutoScalingInstances[0].LifecycleState') | ||
|
||
if [ $STATUS = "Terminating:Wait" ]; then | ||
aws --region $REGION ecs update-container-instances-state --cluster $ECS_CLUSTER --container-instances $ARN --status DRAINING | ||
exit 0 | ||
else | ||
exit 0 | ||
fi |
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,24 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/.$//') | ||
ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | ||
ARN=$(curl -s http://localhost:51678/v1/metadata | jq -r .ContainerInstanceArn) | ||
ECS_CLUSTER=$(curl -s http://localhost:51678/v1/metadata | jq -r .Cluster) | ||
#ASG=$(aws ec2 describe-instances --region $REGION --instance-ids $ID | jq -r '.Reservations[0].Instances[0].Tags[1].Value') | ||
CONTAINER_INSTANCE_STATUS=$(aws --region $REGION ecs describe-container-instances --cluster $ECS_CLUSTER --container-instances "$ARN" | jq -r .containerInstances[0].status) | ||
STATUS=$(aws --region $REGION autoscaling describe-auto-scaling-instances --instance-ids $ID | jq -r '.AutoScalingInstances[0].LifecycleState') | ||
|
||
if [ $STATUS = "InService" ]; then | ||
echo Status is Lifecycle State : $STATUS | ||
echo ECS Instance Status : $CONTAINER_INSTANCE_STATUS | ||
elif [ $STATUS = "Terminating:Wait" ]; then | ||
aws --region $REGION ecs update-container-instances-state --cluster $ECS_CLUSTER --container-instances $ARN --status DRAINING | ||
echo Status is Lifecycle State : $STATUS | ||
echo ECS Instance Status : $CONTAINER_INSTANCE_STATUS | ||
exit 255 | ||
else | ||
echo Status is Lifecycle State : $STATUS | ||
echo ECS Instance Status : $CONTAINER_INSTANCE_STATUS | ||
exit 1 | ||
fi |