Skip to content

Instantly share code, notes, and snippets.

@stefansedich
Created November 16, 2016 20:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefansedich/bd0a4fc69b33a64e8a9a5a59d2e65306 to your computer and use it in GitHub Desktop.
Save stefansedich/bd0a4fc69b33a64e8a9a5a59d2e65306 to your computer and use it in GitHub Desktop.
Running Datadog agent on startup with ECS
Content-Type: multipart/mixed; boundary="==BOUNDARY=="
MIME-Version: 1.0
--==BOUNDARY==
MIME-Version: 1.0
Content-Type: text/x-shellscript; charset="us-ascii"
Content-Disposition: attachment; filename="startup.sh"
#!/bin/bash
cluster="CLUSTER_NAME"
echo ECS_CLUSTER=$cluster >> /etc/ecs/ecs.config
yum install -y aws-cli jq
--==BOUNDARY==
MIME-Version: 1.0
Content-Type: text/upstart-job; charset="us-ascii"
Content-Disposition: attachment; filename="dd-agent.conf"
#upstart-job
description "Datadog Agent"
author "Datadog"
start on started ecs
script
exec 2>>/var/log/ecs/ecs-start-task.log
set -x
until curl -s http://localhost:51678/v1/metadata
do
sleep 1
done
instance_arn=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .ContainerInstanceArn' | awk -F/ '{print $NF}' )
cluster=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .Cluster' | awk -F/ '{print $NF}' )
region=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .ContainerInstanceArn' | awk -F: '{print $4}')
task_definition="TASK_DEFINITION"
aws ecs start-task --cluster $cluster --task-definition $task_definition --container-instances $instance_arn --region $region
end script
--==BOUNDARY==--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment