3
3
set -x
4
4
5
5
# #### Core config #####
6
-
7
- if [[ $DD_API_KEY ]]; then
8
- export API_KEY=${DD_API_KEY}
9
- fi
10
-
11
- if [[ $DD_API_KEY_FILE ]]; then
12
- export API_KEY=$( cat $DD_API_KEY_FILE )
13
- fi
14
-
15
- if [[ $API_KEY ]]; then
16
- sed -i -e " s/^.*api_key:.*$/api_key: ${API_KEY} /" /opt/datadog-agent/agent/datadog.conf
17
- else
18
- echo " You must set API_KEY environment variable to run the Datadog Agent container"
19
- exit 1
20
- fi
21
-
22
- if [[ $DD_HOSTNAME ]]; then
23
- sed -i -r -e " s/^# ?hostname.*$/hostname: ${DD_HOSTNAME} /" /opt/datadog-agent/agent/datadog.conf
24
- fi
25
-
26
- if [[ $DD_TAGS ]]; then
27
- export TAGS=${DD_TAGS}
28
- fi
29
-
30
- if [[ $EC2_TAGS ]]; then
31
- export EC2_TAGS=${EC2_TAGS// \/ / \\ / } # escape forward slashes from tags before invoking sed
32
- sed -i -e " s/^# collect_ec2_tags.*$/collect_ec2_tags: ${EC2_TAGS} /" /opt/datadog-agent/agent/datadog.conf
33
- fi
34
-
35
- if [[ $TAGS ]]; then
36
- export TAGS=${TAGS// \/ / \\ / } # escape forward slashes from tags before invoking sed
37
- sed -i -r -e " s/^# ?tags:.*$/tags: ${TAGS} /" /opt/datadog-agent/agent/datadog.conf
38
- fi
39
-
40
- if [[ $DD_LOG_LEVEL ]]; then
41
- export LOG_LEVEL=$DD_LOG_LEVEL
42
- fi
43
-
44
- if [[ $LOG_LEVEL ]]; then
45
- sed -i -e" s/^.*log_level:.*$/log_level: ${LOG_LEVEL} /" /opt/datadog-agent/agent/datadog.conf
46
- fi
47
-
48
- if [[ $DD_LOGS_STDOUT ]]; then
49
- export LOGS_STDOUT=$DD_LOGS_STDOUT
50
- fi
51
-
52
- if [[ $LOGS_STDOUT == " yes" ]]; then
53
- sed -i -e " /^.*_logfile.*$/d" /opt/datadog-agent/agent/supervisor.conf
54
- sed -i -e " /^.*\[program:.*\].*$/a stdout_logfile=\/dev\/stdout" /opt/datadog-agent/agent/supervisor.conf
55
- sed -i -e " /^.*\[program:.*\].*$/a stdout_logfile_maxbytes=0" /opt/datadog-agent/agent/supervisor.conf
56
- sed -i -e " /^.*\[program:.*\].*$/a stderr_logfile=\/dev\/stderr" /opt/datadog-agent/agent/supervisor.conf
57
- sed -i -e " /^.*\[program:.*\].*$/a stderr_logfile_maxbytes=0" /opt/datadog-agent/agent/supervisor.conf
58
- fi
59
-
60
- if [[ $DD_URL ]]; then
61
- sed -i -e ' s@^.*dd_url:.*$@dd_url: ' ${DD_URL} ' @' /opt/datadog-agent/agent/datadog.conf
62
- fi
63
-
64
- if [[ $STATSD_METRIC_NAMESPACE ]]; then
65
- sed -i -e " s/^# statsd_metric_namespace:.*$/statsd_metric_namespace: ${STATSD_METRIC_NAMESPACE} /" /opt/datadog-agent/agent/datadog.conf
66
- fi
67
-
68
- if [[ $USE_DOGSTATSD ]]; then
69
- sed -i -e " s/^.*use_dogstatsd:.*$/use_dogstatsd: ${USE_DOGSTATSD} /" /opt/datadog-agent/agent/datadog.conf
70
- fi
71
-
72
-
73
- # #### Proxy config #####
74
-
75
- if [[ $PROXY_HOST ]]; then
76
- sed -i -e " s/^# proxy_host:.*$/proxy_host: ${PROXY_HOST} /" /opt/datadog-agent/agent/datadog.conf
77
- fi
78
-
79
- if [[ $PROXY_PORT ]]; then
80
- sed -i -e " s/^# proxy_port:.*$/proxy_port: ${PROXY_PORT} /" /opt/datadog-agent/agent/datadog.conf
81
- fi
82
-
83
- if [[ $PROXY_USER ]]; then
84
- sed -i -e " s/^# proxy_user:.*$/proxy_user: ${PROXY_USER} /" /opt/datadog-agent/agent/datadog.conf
85
- fi
86
-
87
- if [[ $PROXY_PASSWORD ]]; then
88
- sed -i -e " s/^# proxy_password:.*$/proxy_password: ${PROXY_PASSWORD} /" /opt/datadog-agent/agent/datadog.conf
89
- fi
90
-
91
- # #### Service discovery #####
92
- EC2_HOST_IP=` curl --silent http://169.254.169.254/latest/meta-data/local-ipv4 --max-time 1`
93
-
94
- if [[ $SD_BACKEND ]]; then
95
- sed -i -e " s/^# service_discovery_backend:.*$/service_discovery_backend: ${SD_BACKEND} /" /opt/datadog-agent/agent/datadog.conf
96
- fi
97
-
98
- if [[ $SD_CONFIG_BACKEND ]]; then
99
- sed -i -e " s/^# sd_config_backend:.*$/sd_config_backend: ${SD_CONFIG_BACKEND} /" /opt/datadog-agent/agent/datadog.conf
100
- # If no SD_BACKEND_HOST value is defined AND running in EC2 and host ip is available
101
- if [[ -z $SD_BACKEND_HOST && -n $EC2_HOST_IP ]]; then
102
- export SD_BACKEND_HOST=" $EC2_HOST_IP "
103
- fi
104
- fi
105
-
106
- if [[ $SD_BACKEND_HOST ]]; then
107
- sed -i -e " s/^# sd_backend_host:.*$/sd_backend_host: ${SD_BACKEND_HOST} /" /opt/datadog-agent/agent/datadog.conf
108
- fi
109
-
110
- if [[ $SD_BACKEND_PORT ]]; then
111
- sed -i -e " s/^# sd_backend_port:.*$/sd_backend_port: ${SD_BACKEND_PORT} /" /opt/datadog-agent/agent/datadog.conf
112
- fi
113
-
114
- if [[ $SD_TEMPLATE_DIR ]]; then
115
- sed -i -e ' s@^# sd_template_dir:.*$@sd_template_dir: ' ${SD_TEMPLATE_DIR} ' @' /opt/datadog-agent/agent/datadog.conf
116
- fi
117
-
118
- if [[ $SD_CONSUL_TOKEN ]]; then
119
- sed -i -e ' s@^# consul_token:.*$@consul_token: ' ${SD_CONSUL_TOKEN} ' @' /opt/datadog-agent/agent/datadog.conf
120
- fi
121
-
122
- if [[ $SD_BACKEND_USER ]]; then
123
- sed -i -e ' s@^# sd_backend_username:.*$@sd_backend_username: ' ${SD_BACKEND_USER} ' @' /opt/datadog-agent/agent/datadog.conf
124
- fi
125
-
126
- if [[ $SD_BACKEND_PASSWORD ]]; then
127
- sed -i -e ' s@^# sd_backend_password:.*$@sd_backend_password: ' ${SD_BACKEND_PASSWORD} ' @' /opt/datadog-agent/agent/datadog.conf
128
- fi
129
-
130
- # #### Integrations config #####
131
-
132
- if [[ -n " ${KUBERNETES} " || -n " ${MESOS_MASTER} " || -n " ${MESOS_SLAVE} " ]]; then
133
- # expose supervisord as a health check
134
- echo "
135
- [inet_http_server]
136
- port = 0.0.0.0:9001
137
- " >> /opt/datadog-agent/agent/supervisor.conf
138
- fi
139
-
140
- if [[ $KUBERNETES ]]; then
141
- # enable kubernetes check
142
- cp /opt/datadog-agent/agent/conf.d/kubernetes.yaml.example /opt/datadog-agent/agent/conf.d/kubernetes.yaml
143
-
144
- # allows to disable kube_service tagging if needed (big clusters)
145
- if [[ $KUBERNETES_COLLECT_SERVICE_TAGS ]]; then
146
- sed -i -e ' s@# collect_service_tags:.*$@ collect_service_tags: ' ${KUBERNETES_COLLECT_SERVICE_TAGS} ' @' /opt/datadog-agent/agent/conf.d/kubernetes.yaml
147
- fi
148
-
149
- # enable event collector
150
- # WARNING: to avoid duplicates, only one agent at a time across the entire cluster should have this feature enabled.
151
- if [[ $KUBERNETES_COLLECT_EVENTS ]]; then
152
- sed -i -e " s@# collect_events: false@ collect_events: true@" /opt/datadog-agent/agent/conf.d/kubernetes.yaml
153
-
154
- # enable the namespace regex
155
- if [[ $KUBERNETES_NAMESPACE_NAME_REGEX ]]; then
156
- sed -i -e " s@# namespace_name_regexp:@ namespace_name_regexp: ${KUBERNETES_NAMESPACE_NAME_REGEX} @" /opt/datadog-agent/agent/conf.d/kubernetes.yaml
157
- fi
158
- fi
159
- fi
160
-
161
- if [[ $MESOS_MASTER ]]; then
162
- cp /opt/datadog-agent/agent/conf.d/mesos_master.yaml.example /opt/datadog-agent/agent/conf.d/mesos_master.yaml
163
- cp /opt/datadog-agent/agent/conf.d/zk.yaml.example /opt/datadog-agent/agent/conf.d/zk.yaml
164
-
165
- sed -i -e " s/localhost/leader.mesos/" /opt/datadog-agent/agent/conf.d/mesos_master.yaml
166
- sed -i -e " s/localhost/leader.mesos/" /opt/datadog-agent/agent/conf.d/zk.yaml
167
- fi
168
-
169
- if [[ $MESOS_SLAVE ]]; then
170
- cp /opt/datadog-agent/agent/conf.d/mesos_slave.yaml.example /opt/datadog-agent/agent/conf.d/mesos_slave.yaml
171
-
172
- sed -i -e " s/localhost/$HOST /" /opt/datadog-agent/agent/conf.d/mesos_slave.yaml
173
- fi
174
-
175
- if [[ $MARATHON_URL ]]; then
176
- cp /opt/datadog-agent/agent/conf.d/marathon.yaml.example /opt/datadog-agent/agent/conf.d/marathon.yaml
177
- sed -i -e " s@# - url: \" https://server:port\" @- url: ${MARATHON_URL} @" /opt/datadog-agent/agent/conf.d/marathon.yaml
178
- fi
6
+ /opt/datadog-agent/venv/bin/activate && python /config_builder.py
179
7
180
8
find /conf.d -name ' *.yaml' -exec cp --parents {} /opt/datadog-agent/agent \;
181
9
@@ -184,8 +12,6 @@ find /checks.d -name '*.py' -exec cp {} /opt/datadog-agent/agent/checks.d \;
184
12
185
13
# #### Starting up #####
186
14
187
- export PATH=" /opt/datadog-agent/embedded/bin:/opt/datadog-agent/bin:$PATH "
188
-
189
15
if [[ $DOGSTATSD_ONLY ]]; then
190
16
source /opt/datadog-agent/venv/bin/activate && python /opt/datadog-agent/agent/dogstatsd.py
191
17
else
0 commit comments