Skip to content

Instantly share code, notes, and snippets.

@endofcake
Created May 11, 2018 00:35
Show Gist options
  • Save endofcake/120472a9d8c3542dfe75d4f7f813a59c to your computer and use it in GitHub Desktop.
Save endofcake/120472a9d8c3542dfe75d4f7f813a59c 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