From 2c3a26c5fcfe3c3dc7c54796415e900ddab7c3b7 Mon Sep 17 00:00:00 2001 From: Joseph Herlant Date: Thu, 10 Aug 2017 11:52:18 -0700 Subject: [PATCH] Refactor alpine dockerfile and unify entrypoints --- Dockerfile | 7 +- alpine/Dockerfile => Dockerfile-alpine | 55 ++++--- alpine/conf.d/docker_daemon.yaml | 126 ---------------- alpine/entrypoint.sh | 193 ------------------------- entrypoint.sh | 76 +++++----- 5 files changed, 72 insertions(+), 385 deletions(-) rename alpine/Dockerfile => Dockerfile-alpine (58%) delete mode 100644 alpine/conf.d/docker_daemon.yaml delete mode 100755 alpine/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 5b96dc2a..c637350e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ MAINTAINER Datadog ENV DOCKER_DD_AGENT=yes \ AGENT_VERSION=1:5.16.0-1 \ + DD_ETC_ROOT=/etc/dd-agent \ PATH="/opt/datadog-agent/embedded/bin:/opt/datadog-agent/bin:${PATH}" \ PYTHONPATH=/opt/datadog-agent/agent \ DD_CONF_LOG_TO_SYSLOG=no \ @@ -22,13 +23,13 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d # Configure the Agent # 1. Remove dd-agent user from init.d configuration # 2. Fix permission on /etc/init.d/datadog-agent -RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \ +RUN mv ${DD_ETC_ROOT}/datadog.conf.example ${DD_ETC_ROOT}/datadog.conf \ && sed -i 's/AGENTUSER="dd-agent"/AGENTUSER="root"/g' /etc/init.d/datadog-agent \ - && rm -f /etc/dd-agent/conf.d/network.yaml.default \ + && rm -f ${DD_ETC_ROOT}/conf.d/network.yaml.default \ && chmod +x /etc/init.d/datadog-agent # Add Docker check -COPY conf.d/docker_daemon.yaml /etc/dd-agent/conf.d/docker_daemon.yaml +COPY conf.d/docker_daemon.yaml ${DD_ETC_ROOT}/conf.d/docker_daemon.yaml # Add install and config files COPY entrypoint.sh /entrypoint.sh COPY config_builder.py /config_builder.py diff --git a/alpine/Dockerfile b/Dockerfile-alpine similarity index 58% rename from alpine/Dockerfile rename to Dockerfile-alpine index e29fa665..d00d8403 100644 --- a/alpine/Dockerfile +++ b/Dockerfile-alpine @@ -7,50 +7,49 @@ ENV DD_HOME=/opt/datadog-agent \ DD_START_AGENT=0 \ DOCKER_DD_AGENT=yes \ PYCURL_SSL_LIBRARY=openssl \ - AGENT_VERSION=5.16.0 - -# Add Docker check -COPY conf.d/docker_daemon.yaml "$DD_HOME/agent/conf.d/docker_daemon.yaml" - -# Add install and config files -ADD https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh /tmp/setup_agent.sh -COPY entrypoint.sh /entrypoint.sh - -# Expose supervisor and DogStatsD port -EXPOSE 9001/tcp 8125/udp + AGENT_VERSION=5.16.0 \ + DD_ETC_ROOT="/opt/datadog-agent/agent" \ + PATH="/opt/datadog-agent/agent/embedded/bin:/opt/datadog-agent/agent/bin:$PATH" \ + PYTHONPATH="/opt/datadog-agent/agent" \ + DD_CONF_LOG_TO_SYSLOG=no \ + NON_LOCAL_TRAFFIC=yes \ + DD_SUPERVISOR_DELETE_USER=yes # Install minimal dependencies RUN apk add -qU --no-cache coreutils curl curl-dev python-dev tar sysstat tini # Install build dependencies +ADD https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh /tmp/setup_agent.sh RUN apk add -qU --no-cache -t .build-deps gcc musl-dev pgcluster-dev linux-headers \ # Install the agent && sh /tmp/setup_agent.sh \ # Clean build dependencies - && apk del -q .build-deps + && apk del -q .build-deps \ + && rm /tmp/setup_agent.sh # Configure the Agent -# 1. Listen to statsd from other containers -# 2. Turn syslog off -# 3. Remove dd-agent user from supervisor configuration -# 4. Remove setup script -RUN cp "$DD_HOME/agent/datadog.conf.example" "$DD_HOME/agent/datadog.conf" \ - && sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" "$DD_HOME/agent/datadog.conf" \ - && sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" "$DD_HOME/agent/datadog.conf" \ - && sed -i "/user=dd-agent/d" "$DD_HOME/agent/supervisor.conf" \ - && rm "$DD_HOME/agent/conf.d/network.yaml.default" \ - || rm /tmp/setup_agent.sh +RUN cp ${DD_ETC_ROOT}/datadog.conf.example ${DD_ETC_ROOT}/datadog.conf \ + && rm -f ${DD_ETC_ROOT}/conf.d/network.yaml.default + +# Add Docker check +COPY conf.d/docker_daemon.yaml "${DD_ETC_ROOT}/conf.d/docker_daemon.yaml" +# Add install and config files +COPY entrypoint.sh /entrypoint.sh +COPY config_builder.py /config_builder.py + +# Extra conf.d and checks.d +VOLUME ["/conf.d", "/checks.d"] + +# Expose supervisor and DogStatsD port +EXPOSE 9001/tcp 8125/udp # Healthcheck HEALTHCHECK --interval=5m --timeout=3s --retries=1 \ CMD test $($DD_HOME/venv/bin/python $DD_HOME/venv/bin/supervisorctl \ - -c $DD_HOME/agent/supervisor.conf status | awk '{print $2}' | egrep -v 'RUNNING|EXITED' | wc -l) \ + -c ${DD_ETC_ROOT}/supervisor.conf status | awk '{print $2}' | egrep -v 'RUNNING|EXITED' | wc -l) \ -eq 0 || exit 1 -# Extra conf.d and checks.d -VOLUME ["/conf.d", "/checks.d"] - ENTRYPOINT ["/sbin/tini", "-g", "--", "/entrypoint.sh"] -WORKDIR "$DD_HOME" -CMD source venv/bin/activate && supervisord -c agent/supervisor.conf +WORKDIR $DD_HOME +CMD ["supervisord", "-c", "agent/supervisor.conf"] diff --git a/alpine/conf.d/docker_daemon.yaml b/alpine/conf.d/docker_daemon.yaml deleted file mode 100644 index 1c4d76da..00000000 --- a/alpine/conf.d/docker_daemon.yaml +++ /dev/null @@ -1,126 +0,0 @@ -init_config: - # Change the root directory to look at to get cgroup statistics. Useful when running inside a - # container with host directories mounted on a different folder. Default: /. - # Example for the docker-dd-agent container: - docker_root: /host - - # Timeout in seconds for the connection to the docker daemon - # Default: 5 seconds - # - # timeout: 10 - - # The version of the API the client will use. Specify 'auto' to use the API version provided by the server. - # api_version: auto - - # Use TLS encryption while communicating with the Docker API - # - # tls: False - # tls_client_cert: /path/to/client-cert.pem - # tls_client_key: /path/to/client-key.pem - # tls_cacert: /path/to/ca.pem - # tls_verify: True - -instances: - - ## Daemon and system configuration - ## - - # URL of the Docker daemon socket to reach the Docker API. HTTP/HTTPS also works. - # Warning: if that's a non-local daemon, we won't be able to collect performance metrics. - # - url: "unix://var/run/docker.sock" - - ## Data collection - ## - - # Create events whenever a container status change. - # Defaults to true. - # - # collect_events: false - - # Collect disk usage per container with docker.container.size_rw and - # docker.container.size_rootfs metrics. - # Warning: This might take time for Docker daemon to generate, - # ensure that `docker ps -a -q` run fast before enabling it. - # Defaults to false. - # - # collect_container_size: false - - # Collect images stats - # Number of available active images and intermediate images as gauges. - # Defaults to false. - # - # collect_images_stats: false - - # Collect disk usage per image with docker.image.size and docker.image.virtual_size metrics. - # The check gets this size with the `docker images` command. - # Requires collect_images_stats to be enabled. - # Defaults to false. - # - # collect_image_size: false - - # Collect disk metrics (total, used, free) through the docker info command for data and metadata. - # This is useful when these values can't be obtained by the disk check. - # Example: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html - # Note that it only works when the storage driver is devicemapper. - # Explanation of these metrics can be found here: - # https://github.com/docker/docker/blob/v1.11.1/daemon/graphdriver/devmapper/README.md - # Defaults to false. - # - # collect_disk_stats: true - - - # Exclude containers based on their tags - # An excluded container will be completely ignored. The rule is a regex on the tags. - # - # How it works: exclude first. - # If a tag matches an exclude rule, it won't be included unless it also matches an include rule. - # Examples: - # exclude all, except ubuntu and debian. - # exclude: [".*"] - # include: ["docker_image:ubuntu", "docker_image:debian"] - # - # include all, except ubuntu and debian. - # exclude: ["docker_image:ubuntu", "docker_image:debian"] - # include: [] - # - # Default: include all containers - - - - ## Tagging - ## - - # You can add extra tags to your Docker metrics with the tags list option. - # Example: ["extra_tag", "env:testing"] - # - # tags: [] - - # If the agent is running in an Amazon ECS task, tags container metrics with the ECS task name and version. - # Default: true - # - # ecs_tags: false - - # Custom metrics tagging - # Define which Docker tags to apply on metrics. - # Since it impacts the aggregation, modify it carefully (only if you really need it). - # - # Tags for performance metrics. - # Available: - # - image_name: Name of the image (example: "nginx") - # - image_tag: Tag of the image (example: "latest") - # - docker_image: LEGACY. The full image name:tag string (example: "nginx:latest") - # - container_name: Name of the container (example: "boring_euclid") - # - container_command: Command ran by the container (example: "echo 1") - # - container_id: Id of the container - # - # performance_tags: ["container_name", image_name", "image_tag", "docker_image"] - - # Tags for containers count metrics. - # Available: ["image_name", "image_tag", "docker_image", "container_command"] - # - # container_tags: ["image_name", "image_tag", "docker_image"] - - # List of container label names that should be collected and sent as tags. - # Default to None - # Example: - # collect_labels_as_tags: ["com.docker.compose.service", "com.docker.compose.project"] diff --git a/alpine/entrypoint.sh b/alpine/entrypoint.sh deleted file mode 100755 index 665a1974..00000000 --- a/alpine/entrypoint.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/bin/sh -#set -e -set -x - -##### Core config ##### - -if [[ $DD_API_KEY ]]; then - export API_KEY=${DD_API_KEY} -fi - -if [[ $DD_API_KEY_FILE ]]; then - export API_KEY=$(cat $DD_API_KEY_FILE) -fi - -if [[ $API_KEY ]]; then - sed -i -e "s/^.*api_key:.*$/api_key: ${API_KEY}/" /opt/datadog-agent/agent/datadog.conf -else - echo "You must set API_KEY environment variable to run the Datadog Agent container" - exit 1 -fi - -if [[ $DD_HOSTNAME ]]; then - sed -i -r -e "s/^# ?hostname.*$/hostname: ${DD_HOSTNAME}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $DD_TAGS ]]; then - export TAGS=${DD_TAGS} -fi - -if [[ $EC2_TAGS ]]; then - export EC2_TAGS=${EC2_TAGS//\//\\/} # escape forward slashes from tags before invoking sed - sed -i -e "s/^# collect_ec2_tags.*$/collect_ec2_tags: ${EC2_TAGS}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $TAGS ]]; then - export TAGS=${TAGS//\//\\/} # escape forward slashes from tags before invoking sed - sed -i -r -e "s/^# ?tags:.*$/tags: ${TAGS}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $DD_LOG_LEVEL ]]; then - export LOG_LEVEL=$DD_LOG_LEVEL -fi - -if [[ $LOG_LEVEL ]]; then - sed -i -e"s/^.*log_level:.*$/log_level: ${LOG_LEVEL}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $DD_LOGS_STDOUT ]]; then - export LOGS_STDOUT=$DD_LOGS_STDOUT -fi - -if [[ $LOGS_STDOUT == "yes" ]]; then - sed -i -e "/^.*_logfile.*$/d" /opt/datadog-agent/agent/supervisor.conf - sed -i -e "/^.*\[program:.*\].*$/a stdout_logfile=\/dev\/stdout" /opt/datadog-agent/agent/supervisor.conf - sed -i -e "/^.*\[program:.*\].*$/a stdout_logfile_maxbytes=0" /opt/datadog-agent/agent/supervisor.conf - sed -i -e "/^.*\[program:.*\].*$/a stderr_logfile=\/dev\/stderr" /opt/datadog-agent/agent/supervisor.conf - sed -i -e "/^.*\[program:.*\].*$/a stderr_logfile_maxbytes=0" /opt/datadog-agent/agent/supervisor.conf -fi - -if [[ $DD_URL ]]; then - sed -i -e 's@^.*dd_url:.*$@dd_url: '${DD_URL}'@' /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $STATSD_METRIC_NAMESPACE ]]; then - sed -i -e "s/^# statsd_metric_namespace:.*$/statsd_metric_namespace: ${STATSD_METRIC_NAMESPACE}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $USE_DOGSTATSD ]]; then - sed -i -e "s/^.*use_dogstatsd:.*$/use_dogstatsd: ${USE_DOGSTATSD}/" /opt/datadog-agent/agent/datadog.conf -fi - - -##### Proxy config ##### - -if [[ $PROXY_HOST ]]; then - sed -i -e "s/^# proxy_host:.*$/proxy_host: ${PROXY_HOST}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $PROXY_PORT ]]; then - sed -i -e "s/^# proxy_port:.*$/proxy_port: ${PROXY_PORT}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $PROXY_USER ]]; then - sed -i -e "s/^# proxy_user:.*$/proxy_user: ${PROXY_USER}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $PROXY_PASSWORD ]]; then - sed -i -e "s/^# proxy_password:.*$/proxy_password: ${PROXY_PASSWORD}/" /opt/datadog-agent/agent/datadog.conf -fi - -##### Service discovery ##### -EC2_HOST_IP=`curl --silent http://169.254.169.254/latest/meta-data/local-ipv4 --max-time 1` - -if [[ $SD_BACKEND ]]; then - sed -i -e "s/^# service_discovery_backend:.*$/service_discovery_backend: ${SD_BACKEND}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_CONFIG_BACKEND ]]; then - sed -i -e "s/^# sd_config_backend:.*$/sd_config_backend: ${SD_CONFIG_BACKEND}/" /opt/datadog-agent/agent/datadog.conf - # If no SD_BACKEND_HOST value is defined AND running in EC2 and host ip is available - if [[ -z $SD_BACKEND_HOST && -n $EC2_HOST_IP ]]; then - export SD_BACKEND_HOST="$EC2_HOST_IP" - fi -fi - -if [[ $SD_BACKEND_HOST ]]; then - sed -i -e "s/^# sd_backend_host:.*$/sd_backend_host: ${SD_BACKEND_HOST}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_BACKEND_PORT ]]; then - sed -i -e "s/^# sd_backend_port:.*$/sd_backend_port: ${SD_BACKEND_PORT}/" /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_TEMPLATE_DIR ]]; then - sed -i -e 's@^# sd_template_dir:.*$@sd_template_dir: '${SD_TEMPLATE_DIR}'@' /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_CONSUL_TOKEN ]]; then - sed -i -e 's@^# consul_token:.*$@consul_token: '${SD_CONSUL_TOKEN}'@' /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_BACKEND_USER ]]; then - sed -i -e 's@^# sd_backend_username:.*$@sd_backend_username: '${SD_BACKEND_USER}'@' /opt/datadog-agent/agent/datadog.conf -fi - -if [[ $SD_BACKEND_PASSWORD ]]; then - sed -i -e 's@^# sd_backend_password:.*$@sd_backend_password: '${SD_BACKEND_PASSWORD}'@' /opt/datadog-agent/agent/datadog.conf -fi - -##### Integrations config ##### - -if [[ -n "${KUBERNETES}" || -n "${MESOS_MASTER}" || -n "${MESOS_SLAVE}" ]]; then - # expose supervisord as a health check - echo " -[inet_http_server] -port = 0.0.0.0:9001 -" >> /opt/datadog-agent/agent/supervisor.conf -fi - -if [[ $KUBERNETES ]]; then - # enable kubernetes check - cp /opt/datadog-agent/agent/conf.d/kubernetes.yaml.example /opt/datadog-agent/agent/conf.d/kubernetes.yaml - - # allows to disable kube_service tagging if needed (big clusters) - if [[ $KUBERNETES_COLLECT_SERVICE_TAGS ]]; then - sed -i -e 's@# collect_service_tags:.*$@ collect_service_tags: '${KUBERNETES_COLLECT_SERVICE_TAGS}'@' /opt/datadog-agent/agent/conf.d/kubernetes.yaml - fi - - # enable event collector - # WARNING: to avoid duplicates, only one agent at a time across the entire cluster should have this feature enabled. - if [[ $KUBERNETES_COLLECT_EVENTS ]]; then - sed -i -e "s@# collect_events: false@ collect_events: true@" /opt/datadog-agent/agent/conf.d/kubernetes.yaml - - # enable the namespace regex - if [[ $KUBERNETES_NAMESPACE_NAME_REGEX ]]; then - sed -i -e "s@# namespace_name_regexp:@ namespace_name_regexp: ${KUBERNETES_NAMESPACE_NAME_REGEX}@" /opt/datadog-agent/agent/conf.d/kubernetes.yaml - fi - fi -fi - -if [[ $MESOS_MASTER ]]; then - cp /opt/datadog-agent/agent/conf.d/mesos_master.yaml.example /opt/datadog-agent/agent/conf.d/mesos_master.yaml - cp /opt/datadog-agent/agent/conf.d/zk.yaml.example /opt/datadog-agent/agent/conf.d/zk.yaml - - sed -i -e "s/localhost/leader.mesos/" /opt/datadog-agent/agent/conf.d/mesos_master.yaml - sed -i -e "s/localhost/leader.mesos/" /opt/datadog-agent/agent/conf.d/zk.yaml -fi - -if [[ $MESOS_SLAVE ]]; then - cp /opt/datadog-agent/agent/conf.d/mesos_slave.yaml.example /opt/datadog-agent/agent/conf.d/mesos_slave.yaml - - sed -i -e "s/localhost/$HOST/" /opt/datadog-agent/agent/conf.d/mesos_slave.yaml -fi - -if [[ $MARATHON_URL ]]; then - cp /opt/datadog-agent/agent/conf.d/marathon.yaml.example /opt/datadog-agent/agent/conf.d/marathon.yaml - sed -i -e "s@# - url: \"https://server:port\"@- url: ${MARATHON_URL}@" /opt/datadog-agent/agent/conf.d/marathon.yaml -fi - -find /conf.d -name '*.yaml' -exec cp --parents {} /opt/datadog-agent/agent \; - -find /checks.d -name '*.py' -exec cp {} /opt/datadog-agent/agent/checks.d \; - - -##### Starting up ##### - -export PATH="/opt/datadog-agent/embedded/bin:/opt/datadog-agent/bin:$PATH" - -if [[ $DOGSTATSD_ONLY ]]; then - source /opt/datadog-agent/venv/bin/activate && python /opt/datadog-agent/agent/dogstatsd.py -else - exec "$@" -fi diff --git a/entrypoint.sh b/entrypoint.sh index 29b47fb5..6b742832 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,93 +1,99 @@ -#!/bin/bash +#!/bin/sh #set -e +# When using venv, activate it 1st +if [ -n $DD_HOME ]; then + if [ -f "${DD_HOME}/venv/bin/activate" ]; then + source ${DD_HOME}/venv/bin/activate + fi +fi ##### Core config ##### -/opt/datadog-agent/embedded/bin/python /config_builder.py +python /config_builder.py -if [[ "${DD_SUPERVISOR_DELETE_USER}" == "yes" ]]; then - sed -i "/user=dd-agent/d" /etc/dd-agent/supervisor.conf +if [ "${DD_SUPERVISOR_DELETE_USER}" = "yes" ]; then + sed -i "/user=dd-agent/d" ${DD_ETC_ROOT}/supervisor.conf fi -if [[ $DD_LOGS_STDOUT ]]; then +if [ $DD_LOGS_STDOUT ]; then export LOGS_STDOUT=$DD_LOGS_STDOUT fi -if [[ "$LOGS_STDOUT" == "yes" ]]; then - sed -i -e "/^.*_logfile.*$/d" /etc/dd-agent/supervisor.conf - sed -i -e "/^.*\[program:.*\].*$/a stdout_logfile=\/dev\/stdout\nstdout_logfile_maxbytes=0\nstderr_logfile=\/dev\/stderr\nstderr_logfile_maxbytes=0" /etc/dd-agent/supervisor.conf +if [ "$LOGS_STDOUT" = "yes" ]; then + sed -i -e "/^.*_logfile.*$/d" ${DD_ETC_ROOT}/supervisor.conf + sed -i -e "/^.*\[program:.*\].*$/a stdout_logfile=\/dev\/stdout\nstdout_logfile_maxbytes=0\nstderr_logfile=\/dev\/stderr\nstderr_logfile_maxbytes=0" ${DD_ETC_ROOT}/supervisor.conf fi ##### Integrations config ##### -if [[ $KUBERNETES || $MESOS_MASTER || $MESOS_SLAVE ]]; then +if [ $KUBERNETES ] || [ $MESOS_MASTER ] || [ $MESOS_SLAVE ]; then # expose supervisord as a health check echo " [inet_http_server] port = 0.0.0.0:9001 -" >> /etc/dd-agent/supervisor.conf +" >> ${DD_ETC_ROOT}/supervisor.conf fi -if [[ $KUBERNETES ]]; then +if [ $KUBERNETES ]; then # enable kubernetes check - cp /etc/dd-agent/conf.d/kubernetes.yaml.example /etc/dd-agent/conf.d/kubernetes.yaml + cp ${DD_ETC_ROOT}/conf.d/kubernetes.yaml.example ${DD_ETC_ROOT}/conf.d/kubernetes.yaml # allows to disable kube_service tagging if needed (big clusters) - if [[ $KUBERNETES_COLLECT_SERVICE_TAGS ]]; then - sed -i -e 's@# collect_service_tags:.*$@ collect_service_tags: '${KUBERNETES_COLLECT_SERVICE_TAGS}'@' /etc/dd-agent/conf.d/kubernetes.yaml + if [ $KUBERNETES_COLLECT_SERVICE_TAGS ]; then + sed -i -e 's@# collect_service_tags:.*$@ collect_service_tags: '${KUBERNETES_COLLECT_SERVICE_TAGS}'@' ${DD_ETC_ROOT}/conf.d/kubernetes.yaml fi # enable event collector # WARNING: to avoid duplicates, only one agent at a time across the entire cluster should have this feature enabled. - if [[ $KUBERNETES_COLLECT_EVENTS ]]; then - sed -i -e "s@# collect_events: false@ collect_events: true@" /etc/dd-agent/conf.d/kubernetes.yaml + if [ $KUBERNETES_COLLECT_EVENTS ]; then + sed -i -e "s@# collect_events: false@ collect_events: true@" ${DD_ETC_ROOT}/conf.d/kubernetes.yaml # enable the namespace regex - if [[ $KUBERNETES_NAMESPACE_NAME_REGEX ]]; then - sed -i -e "s@# namespace_name_regexp:@ namespace_name_regexp: ${KUBERNETES_NAMESPACE_NAME_REGEX}@" /etc/dd-agent/conf.d/kubernetes.yaml + if [ $KUBERNETES_NAMESPACE_NAME_REGEX ]; then + sed -i -e "s@# namespace_name_regexp:@ namespace_name_regexp: ${KUBERNETES_NAMESPACE_NAME_REGEX}@" ${DD_ETC_ROOT}/conf.d/kubernetes.yaml fi fi fi -if [[ $MESOS_MASTER ]]; then - cp /etc/dd-agent/conf.d/mesos_master.yaml.example /etc/dd-agent/conf.d/mesos_master.yaml - cp /etc/dd-agent/conf.d/zk.yaml.example /etc/dd-agent/conf.d/zk.yaml +if [ $MESOS_MASTER ]; then + cp ${DD_ETC_ROOT}/conf.d/mesos_master.yaml.example ${DD_ETC_ROOT}/conf.d/mesos_master.yaml + cp ${DD_ETC_ROOT}/conf.d/zk.yaml.example ${DD_ETC_ROOT}/conf.d/zk.yaml - sed -i -e "s/localhost/leader.mesos/" /etc/dd-agent/conf.d/mesos_master.yaml - sed -i -e "s/localhost/leader.mesos/" /etc/dd-agent/conf.d/zk.yaml + sed -i -e "s/localhost/leader.mesos/" ${DD_ETC_ROOT}/conf.d/mesos_master.yaml + sed -i -e "s/localhost/leader.mesos/" ${DD_ETC_ROOT}/conf.d/zk.yaml fi -if [[ $MESOS_SLAVE ]]; then - cp /etc/dd-agent/conf.d/mesos_slave.yaml.example /etc/dd-agent/conf.d/mesos_slave.yaml +if [ $MESOS_SLAVE ]; then + cp ${DD_ETC_ROOT}/conf.d/mesos_slave.yaml.example ${DD_ETC_ROOT}/conf.d/mesos_slave.yaml - sed -i -e "s/localhost/$HOST/" /etc/dd-agent/conf.d/mesos_slave.yaml + sed -i -e "s/localhost/$HOST/" ${DD_ETC_ROOT}/conf.d/mesos_slave.yaml fi -if [[ $MARATHON_URL ]]; then - cp /etc/dd-agent/conf.d/marathon.yaml.example /etc/dd-agent/conf.d/marathon.yaml - sed -i -e "s@# - url: \"https://server:port\"@- url: ${MARATHON_URL}@" /etc/dd-agent/conf.d/marathon.yaml +if [ $MARATHON_URL ]; then + cp ${DD_ETC_ROOT}/conf.d/marathon.yaml.example ${DD_ETC_ROOT}/conf.d/marathon.yaml + sed -i -e "s@# - url: \"https://server:port\"@- url: ${MARATHON_URL}@" ${DD_ETC_ROOT}/conf.d/marathon.yaml fi -find /conf.d -name '*.yaml' -exec cp --parents {} /etc/dd-agent \; +find /conf.d -name '*.yaml' -exec cp --parents {} ${DD_ETC_ROOT} \; -find /checks.d -name '*.py' -exec cp --parents {} /etc/dd-agent \; +find /checks.d -name '*.py' -exec cp --parents {} ${DD_ETC_ROOT} \; ##### Starting up ##### -if [[ -z $DD_HOSTNAME && $DD_APM_ENABLED ]]; then +if [ -z $DD_HOSTNAME ] && [ $DD_APM_ENABLED ]; then # When starting up the trace-agent without an explicit hostname # we need to ensure that the trace-agent will report as the same host as the # infrastructure agent. # To do this, we execute some of dd-agent's python code and expose the hostname # as an env var - export DD_HOSTNAME=`PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python -c "from utils.hostname import get_hostname; print get_hostname()"` + export DD_HOSTNAME=`python -c "from utils.hostname import get_hostname; print get_hostname()"` fi -if [[ $DOGSTATSD_ONLY ]]; then +if [ $DOGSTATSD_ONLY ]; then echo "[WARNING] This option is deprecated as of agent 5.8.0, it will be removed in the next few versions. Please use the dogstatsd image instead." - PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python /opt/datadog-agent/agent/dogstatsd.py + python /opt/datadog-agent/agent/dogstatsd.py else exec "$@" fi