Stop logstash if elasticsearch is unreachable


I have written a bash script that does the following:

for each file in the input folder, feed the file to logstash for processing and send that to elasticsearch.
Once the file has been processed it moves it to the processed folder.

#! /bin/bash
if [[ $# -lt 2 ]] ; then
    exit 0
for filename in $INPUT_PATH/*.log; do
	bin/logstash -f config/logstash.conf < $filename
	mv $filename $OUTPUT_PATH

The problem arises when the Elasticseach instance is down and logstash gets into an infinite reconnection loop. Is there any way to make logstash shut down when it fails to reach the elasticseach instance?

[WARN ] 2019-11-19 09:45:42.930 [Ruby-0-Thread-4: :1] elasticsearch - Attempted to resurrect connection to dead ES instance, but got an error. {:url=>"", :error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :error=>"Elasticsearch Unreachable: [][Manticore::ConnectTimeout] connect timed out"}

I must use this method as it is the only one that allows me to run logstash on demand using cron. If the ES instance is up, the script runs just fine.

Thanks in advance,

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.