diff --git a/docker-compose.setup.yml b/docker-compose.setup.yml index 50acaea..f128424 100644 --- a/docker-compose.setup.yml +++ b/docker-compose.setup.yml @@ -117,10 +117,10 @@ services: image: docker.elastic.co/apm/apm-server:${TAG} container_name: setup_apm_server user: root - command: ['/bin/bash', '-c', 'cat /usr/local/bin/setup-beat.sh | tr -d "\r" | bash -s apm-server'] + command: ['/bin/bash', '-c', 'cat /usr/local/bin/setup-apm-server.sh | tr -d "\r" | bash'] volumes: - './config:/config' - - './scripts/setup-beat.sh:/usr/local/bin/setup-beat.sh:ro' + - './scripts/setup-apm-server.sh:/usr/local/bin/setup-apm-server.sh:ro' - './config/apm-server/apm-server.yml:/usr/share/apm-server/apm-server.yml' - './config/ssl/ca/ca.crt:/usr/share/apm-server/certs/ca/ca.crt' environment: ['ELASTIC_PASSWORD=${ELASTIC_PASSWORD}'] diff --git a/docker-compose.yml b/docker-compose.yml index 346dd61..9cbbf26 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -230,7 +230,7 @@ services: - source: ca.crt target: /usr/share/apm-server/certs/ca/ca.crt volumes: - - './scripts/setup-beat.sh:/usr/local/bin/setup-beat.sh:ro' + - './scripts/setup-apm-server.sh:/usr/local/bin/setup-apm-server.sh:ro' depends_on: ['elasticsearch', 'kibana'] healthcheck: test: curl --cacert /usr/share/elasticsearch/config/certs/ca/ca.crt -s https://localhost:8200/healthcheck >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi diff --git a/scripts/setup-apm-server.sh b/scripts/setup-apm-server.sh new file mode 100755 index 0000000..d577610 --- /dev/null +++ b/scripts/setup-apm-server.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -euo pipefail + +until curl -s "http://kibana:5601/login" | grep "Loading Kibana" > /dev/null; do + echo "Waiting for kibana..." + sleep 5 +done + +# apm-server.yml needs to be owned by root +chown root /usr/share/apm-server/apm-server.yml + +echo "Creating keystore..." +echo "y" | /usr/share/apm-server/apm-server keystore create --force + +echo "Adding ELASTIC_PASSWORD to keystore..." +echo "$ELASTIC_PASSWORD" | /usr/share/apm-server/apm-server keystore add 'ELASTIC_PASSWORD' --stdin +/usr/share/apm-server/apm-server keystore list + +echo "Setting up dashboards..." +# Load the sample dashboards for APM. +# REF: https://www.elastic.co/guide/en/apm/server/current/load-kibana-dashboards.html +/usr/share/apm-server/apm-server setup --dashboards + +echo "Copy keystore to ./config dir" +mv /usr/share/apm-server/apm-server.keystore /config/apm-server/apm-server.keystore +chown 1000:1000 /config/apm-server/apm-server.keystore diff --git a/scripts/setup-beat.sh b/scripts/setup-beat.sh index 57d6458..7e202e2 100755 --- a/scripts/setup-beat.sh +++ b/scripts/setup-beat.sh @@ -6,7 +6,7 @@ beat=$1 until curl -s "http://kibana:5601/login" | grep "Loading Kibana" > /dev/null; do echo "Waiting for kibana..." - sleep 1 + sleep 5 done chmod go-w /usr/share/$beat/$beat.yml