Skip to content

Instantly share code, notes, and snippets.

@include
Forked from endofcake/userdata.sh
Created November 22, 2018 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save include/5fedec9a885e5f8118d3fe8239dd511b to your computer and use it in GitHub Desktop.
Save include/5fedec9a885e5f8118d3fe8239dd511b to your computer and use it in GitHub Desktop.
Check that ecs-agent is running and signal back to CloudFormation
#!/bin/bash
set -euo pipefail
<...>
echo "Checking that agent is running"
until $(curl --output /dev/null --silent --head --fail http://localhost:51678/v1/metadata); do
printf '.'
sleep 1
done
exit_code=$?
printf "\nDone\n"
# Can't signal back if the stack is in UPDATE_COMPLETE state, so ignore failures to do so.
# CFN will roll back if it expects the signal but doesn't get it anyway.
echo "Reporting $exit_code exit code to Cloudformation"
/opt/aws/bin/cfn-signal \
--exit-code "$exit_code" \
--stack "$CFN_STACK" \
--resource ASG \
--region "$REGION" || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment