This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
34 lines (31 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[Unit]
Description=ElasticSearch 5.1.1
Documentation=https://github.com/gaia-adm/docker-elasticsearch
After=registrator.service
Wants=registrator.service
[Service]
LimitMEMLOCK=infinity
LimitCORE=infinity
TimeoutStartSec=10min
TimeoutStopSec=15
KillMode=none
EnvironmentFile=/etc/environment
Restart=on-failure
RestartSec=20s
ExecStartPre=/usr/bin/sudo sysctl vm.max_map_count=262144
ExecStartPre=-/usr/bin/docker kill es-%i
ExecStartPre=-/usr/bin/docker rm es-%i
ExecStartPre=/usr/bin/docker pull gaiaadm/volume-tools-${ENVIRON_LOCATION}:0.2.0
ExecStartPre=/usr/bin/docker run --rm=true -v /opt/bin:/target gaiaadm/volume-tools-${ENVIRON_LOCATION}:0.2.0
ExecStartPre=/opt/bin/gaia-mount.sh es-%i-${ENVIRON}
ExecStart=/bin/bash -a -c 'mem=$(($( /usr/bin/cat /proc/meminfo | head -1 | tr -s " " | cut -d " " -f 2) / 2 / 1024 ))m; echo "memory settings are $mem"; if [[ $(systemctl show-environment | grep ENVIRON_LOCATION | cut -d= -f2) == "vagrant" ]]; then nethost=-Enetwork.host=0.0.0.0; /usr/bin/docker run --ulimit memlock=-1:-1 --name es-%i -h es-%i.skydns.local -p 9300:9300 -p 9200:9200 -v $(/opt/bin/gaia-get-mount-path.sh es-%i-${ENVIRON}/data):/usr/share/elasticsearch/data -e ES_JAVA_OPTS="-Xms$mem -Xmx$mem" -e SERVICE_NAME=es -e SERVICE_TAGS=master,es-node-%i gaiaadm/elastic-vagrant elasticsearch $nethost -Enetwork.bind_host=0.0.0.0 -Ecluster.name=${ENVIRON} -Enode.name=${ENVIRON}-%i ; else /usr/bin/docker run --ulimit memlock=-1:-1 --name es-%i -p 9300:9300 -p 9200:9200 -v $(/opt/bin/gaia-get-mount-path.sh es-%i-${ENVIRON}/data):/usr/share/elasticsearch/data -e AWS_REGION=${AWS_REGION} -e AWS_ACCESS_KEY_ID=$(systemctl show-environment | grep AWS_ACCESS_KEY= | cut -d "=" -f 2) -e AWS_SECRET_ACCESS_KEY=$(systemctl show-environment | grep AWS_SECRET_KEY= | cut -d "=" -f 2) -e ES_JAVA_OPTS="-Xms$mem -Xmx$mem" -e SERVICE_NAME=es -e SERVICE_TAGS=master,es-node-%i gaiaadm/elasticsearch:37-master elasticsearch $nethost -Enetwork.bind_host=0.0.0.0 -Ecluster.name=${ENVIRON} -Enode.name=${ENVIRON}-%i; fi; '
ExecStartPost=/bin/bash -c 'echo "es fleet unit - ExecStartPost - sleep looping until ES is up and running"; until [ "$(curl -o /dev/null --silent --write-out %{http_code} http://localhost:9200/_cluster/state)" -eq "200" ]; do sleep 0.1; done; echo "es fleet unit - ExecStartPost - ES is up and running - going to apply gaia mapping using REST API"; /bin/curl -H "Content-Type: application/json" --silent -X POST -d "{\\\"template\\\":\\\"gaia*\\\",\\\"mappings\\\":{\\\"_default_\\\":{\\\"dynamic_templates\\\":[{\\\"strings\\\":{\\\"match_mapping_type\\\":\\\"string\\\",\\\"mapping\\\":{\\\"type\\\":\\\"string\\\",\\\"index\\\":\\\"not_analyzed\\\"}}}]}}}" http://localhost:9200/_template/gaia_template; /bin/curl -H "Content-Type: application/json" --silent -X POST -d "{\\\"template\\\":\\\"tugbot*\\\",\\\"mappings\\\":{\\\"_default_\\\":{\\\"dynamic_templates\\\":[{\\\"strings\\\":{\\\"match_mapping_type\\\":\\\"string\\\",\\\"mapping\\\":{\\\"type\\\":\\\"string\\\",\\\"index\\\":\\\"not_analyzed\\\"}}}]}}}" http://localhost:9200/_template/tugbot_template; echo "\nes fleet unit - ExecStartPost - finished applying gaia mapping using REST API"'
ExecStartPost=/bin/bash -ac 'LOC=$(systemctl show-environment | grep ENVIRON_LOCATION= | cut -d "=" -f 2); if [[ "$LOC" == "amazon" ]]; then REG=$(systemctl show-environment | grep AWS_REGION= | cut -d "=" -f 2); echo LOC=$LOC; echo REG=$REG ; if ([[ $LOC="amazon" ]] && [[ $REG ]]); then (ENVIR=$(systemctl show-environment | grep ENVIRON= | cut -d "=" -f 2); DOM=$(systemctl show-environment | grep DOMAIN= | cut -d "=" -f 2); if [[ -z $DOM ]]; then DOM=master; fi; /bin/curl --silent -X PUT -d "{\\\"type\\\":\\\"s3\\\", \\\"settings\\\":{\\\"bucket\\\":\\\"gaia.backup-$DOM-$ENVIR-$REG\\\", \\\"region\\\":\\\"$REG\\\",\\\"base_path\\\":\\\"elastic-backup\\\"}}" http://localhost:9200/_snapshot/s3_repository/); fi; else echo NOT RUNNING IN AWS, NO NEED TO SET REPOSITORY; fi; '
ExecStop=/usr/bin/docker stop es-%i
ExecStop=-/opt/bin/gaia-unmount.sh es-%i-${ENVIRON}
ExecStopPost=-/opt/bin/gaia-unmount.sh es-%i-${ENVIRON}
[Install]
WantedBy=multi-user.target
[X-Fleet]
Conflicts=es@*.service
MachineMetadata=elasticsearch=true