Created
June 17, 2019 05:04
-
-
Save chrisz100/5e1f3cab046c5662ae625998b3abaa6a to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
while sleep 5; do | |
if [ -z \$(curl -Isf http://169.254.169.254/latest/meta-data/spot/termination-time)];then | |
/bin/false | |
else | |
logger "[spot-instance-termination-notice-handler.sh]: spot instance terminationnotice detected" | |
STATUS=DRAINING | |
ECS_CLUSTER=\$(curl -s http://localhost:51678/v1/metadata | jq .Cluster | tr -d \") | |
CONTAINER_INSTANCE=\$(curl -s http://localhost:51678/v1/metadata | jq .ContainerInstanceArn| tr -d \") | |
logger "[spot-instance-termination-notice-handler.sh]: putting instance in state\$STATUS" | |
logger "[spot-instance-termination-notice-handler.sh]: running: /bin/aws ecs update-container-instances-state --cluster \$ECS_CLUSTER --container-instances \$CONTAINER_INSTANCE --status \$STATUS" | |
/bin/aws ecs update-container-instances-state --cluster \$ECS_CLUSTER --container-instance \$CONTAINER_INSTANCE --status \$STATUS | |
logger "[spot-instance-termination-notice-handler.sh]: putting myself to sleep..." | |
sleep 120 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment