Created
November 16, 2016 20:23
-
-
Save stefansedich/bd0a4fc69b33a64e8a9a5a59d2e65306 to your computer and use it in GitHub Desktop.
Running Datadog agent on startup with ECS
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
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