Until recently, using Elastic 7.11.2, I've been using the following curl command line, in a Linux shell script, to detect whether Logstash is ready to ingest data:
curl localhost:9600 2> /dev/null
(In a previous edit of this question, I mistakenly wrote that "an empty response means success". That was bogus, wrongheaded.)
Now that I've upgraded to 7.13.2, that technique no longer works. I gather from the log that there's now a longer delay between that successful response and the pipeline actually being ready. (Perhaps I've just been lucky so far. Perhaps it was never a good technique.)
The socat
TCP forwarder that I call (this particular pipeline uses a tcp input), following a successful response from curl, now displays the error:
socat[525] E connect(6, AF=2 127.0.0.1:5046, 16): Connection refused
However, if I insert a /bin/sleep 10
before the call to socat
, it works again.
I hate inserting arbitrary "sleep for n seconds" steps in scripts!
I'm considering a successful response (code 200) to the following request as an option:
curl -LI 'localhost:9600/_node/pipelines/main' -o /dev/null -w '%{http_code}\n' -s
but I haven't fully tested whether this is a reliable indicator.
Another option: keep trying socat
until it works. Perhaps:
socat /dev/null TCP4:localhost:5046
(5046 is the port on which the Logstash tcp input is configured to listen)
I welcome alternative recommendations for a telltale API request/response.
Note: I need to test not just that the Logstash service is running, but that a particular pipeline (e.g. main) is ready for input.