Only load pipelines on change

This commit is contained in:
Mike Reeves
2022-03-07 14:25:46 -05:00
parent eac120f4c2
commit d33db6fb23
2 changed files with 35 additions and 24 deletions

View File

@@ -268,6 +268,15 @@ es_repo_dir:
- require: - require:
- file: nsmesdir - file: nsmesdir
so-pipelines-reload:
cmd.run:
- name: rm -r /opt/so/state/espipelines.txt
- onchanges:
- file: esingestconf
- file: esingestdynamicconf
- file: esyml
- file: so-elasticsearch-pipelines-script
auth_users: auth_users:
file.managed: file.managed:
- name: /opt/so/conf/elasticsearch/users.tmp - name: /opt/so/conf/elasticsearch/users.tmp
@@ -397,11 +406,6 @@ so-elasticsearch-templates:
so-elasticsearch-pipelines: so-elasticsearch-pipelines:
cmd.run: cmd.run:
- name: /usr/sbin/so-elasticsearch-pipelines {{ grains.host }} - name: /usr/sbin/so-elasticsearch-pipelines {{ grains.host }}
- onchanges:
- file: esingestconf
- file: esingestdynamicconf
- file: esyml
- file: so-elasticsearch-pipelines-script
- require: - require:
- docker_container: so-elasticsearch - docker_container: so-elasticsearch
- file: so-elasticsearch-pipelines-script - file: so-elasticsearch-pipelines-script

View File

@@ -23,33 +23,40 @@ ELASTICSEARCH_PORT=9200
ELASTICSEARCH_INGEST_PIPELINES="/opt/so/conf/elasticsearch/ingest/" ELASTICSEARCH_INGEST_PIPELINES="/opt/so/conf/elasticsearch/ingest/"
# Wait for ElasticSearch to initialize # Wait for ElasticSearch to initialize
echo -n "Waiting for ElasticSearch..."
COUNT=0 if [ ! -f /opt/so/state/espipelines.txt ]; then
ELASTICSEARCH_CONNECTED="no"
while [[ "$COUNT" -le 240 ]]; do echo -n "Waiting for ElasticSearch..."
{{ ELASTICCURL }} -k --output /dev/null --silent --head --fail -L https://"$ELASTICSEARCH_HOST":"$ELASTICSEARCH_PORT" COUNT=0
if [ $? -eq 0 ]; then ELASTICSEARCH_CONNECTED="no"
ELASTICSEARCH_CONNECTED="yes" while [[ "$COUNT" -le 240 ]]; do
{{ ELASTICCURL }} -k --output /dev/null --silent --head --fail -L https://"$ELASTICSEARCH_HOST":"$ELASTICSEARCH_PORT"
if [ $? -eq 0 ]; then
ELASTICSEARCH_CONNECTED="yes"
echo "connected!" echo "connected!"
break break
else else
((COUNT+=1)) ((COUNT+=1))
sleep 1 sleep 1
echo -n "." echo -n "."
fi fi
done done
if [ "$ELASTICSEARCH_CONNECTED" == "no" ]; then if [ "$ELASTICSEARCH_CONNECTED" == "no" ]; then
echo echo
echo -e "Connection attempt timed out. Unable to connect to ElasticSearch. \nPlease try: \n -checking log(s) in /var/log/elasticsearch/\n -running 'sudo docker ps' \n -running 'sudo so-elastic-restart'" echo -e "Connection attempt timed out. Unable to connect to ElasticSearch. \nPlease try: \n -checking log(s) in /var/log/elasticsearch/\n -running 'sudo docker ps' \n -running 'sudo so-elastic-restart'"
echo echo
fi
cd ${ELASTICSEARCH_INGEST_PIPELINES}
echo "Loading pipelines..."
for i in *; do echo $i; RESPONSE=$({{ ELASTICCURL }} -k -XPUT -L https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_ingest/pipeline/$i -H 'Content-Type: application/json' -d@$i 2>/dev/null); echo $RESPONSE; if [[ "$RESPONSE" == *"error"* ]]; then RETURN_CODE=1; fi; done
echo
cd - >/dev/null
if [[ "$RETURN_CODE" != "1" ]]; then
touch /opt/so/state/espipelines.txt
fi
else
exit $RETURN_CODE
fi fi
cd ${ELASTICSEARCH_INGEST_PIPELINES}
echo "Loading pipelines..."
for i in *; do echo $i; RESPONSE=$({{ ELASTICCURL }} -k -XPUT -L https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_ingest/pipeline/$i -H 'Content-Type: application/json' -d@$i 2>/dev/null); echo $RESPONSE; if [[ "$RESPONSE" == *"error"* ]]; then RETURN_CODE=1; fi; done
echo
cd - >/dev/null
exit $RETURN_CODE