情况:
dailyImport.sh
docker exec -it $DOCKER_CONTAINER_NAME opt/logstash/bin/logstash --path.data /tmp/logstash/data -e \
'input {
file {
path => "'$OUTPUT_PATH'"
start_position => "beginning"
sincedb_path => "/dev/null"
mode => "read"
file_completed_action => "delete"
}
}
filter {
csv {
separator => ","
columns => ["foo", "bar", "foo2", "bar2"]
}
}
output {
elasticsearch{
hosts => "localhost:9200"
index => "foo"
document_type => "foo"
}
stdout {}
}'
我尝试过并理解的:
read
模式和 file_completed_action
删除会停止操作,我尝试了但没有成功。Ctrl + C
来停止管道。例如:^C[2019-02-21T15:49:07,787][WARN ][logstash.runner ] SIGINT received. Shutting down.
[2019-02-21T15:49:07,899][INFO ][filewatch.observingread ] QUIT - closing all files and shutting down.
[2019-02-21T15:49:09,764][INFO ][logstash.pipeline ] Pipeline has terminated {:pipeline_id=>"main", :thread=>"#<Thread:0x6bdb92ea run>"}
Done
我已读到我可以执行以下操作,但不知道如何操作:
参考:https://discuss.elastic.co/t/stop-logstash-after-processing-the-file/84959
我想要的:
Ctrl + C
。对于文件输入,在读取模式下,有一种方法可以在读取完所有文件后退出进程,只需设置:
input { file { exit_after_read => true } }
如何在
dailyImport.sh
的输出中运行一个脚本,不断检查 Elasticsearch 中的预期数据,然后在完成后终止 Logstash 进程?
不太优雅,但就我而言就足够了。
if curl 'http://eslasticsearch:9200/index/_count | grep -q "count: 100"; then
#Kill Logstash service so container would stop
kill $(ps aux | grep 'logstash' | awk '{print $2}')
break
else
echo "Counting documents from Elasticsearch does not return the expected number. Retrying"
sleep 2
fi