Script after kibana initialization

Hello. I have created a canvas and would like to make sure anyone using my docker-compose file has it as soon as the ELK stack initializes.
For that purpose I wrote the following script:

#!/bin/bash

response=$(curl -so /dev/null -w "%{http_code}\n" localhost:5601/status)
while [ $response != "200" ]
do
response=$(curl -so /dev/null -w "%{http_code}\n" localhost:5601/status)
echo WAITING
sleep 5
done


curl -X POST localhost:5601/api/saved_objects/_import -H "kbn-xsrf: true" --form file=@test.ndjson

Now I call this from a Dockerfile:

FROM kibana:7.9.1
COPY script.sh /scripts/script.sh
ENTRYPOINT /scripts/script.sh

And I call this from docker-compose.yml:

 kibana:
    build: ./kibana

The problem is that when using docker-compose build and the docker compose up all I see is WAITING printed on the console, this tells me that the script is being called but for some reason kibana fails to initiate.

Is there anyway this can be done? (calling a curl right after kibana has started)

OK, what I did was the following:

Make sure that the kibana image is being created from a dockerfile:

kibana:
    build: ./kibana
    container_name: kibana
    ports:
      - 5601:5601
    environment:
      ELASTICSEARCH_URL: http://elasticsearch:9200
      ELASTICSEARCH_HOSTS: http://elasticsearch:9200
    depends_on:
      - elasticsearch

Then in the dockerfile pass the canvas to the container's filessystem along with a modified version of the init script:

FROM kibana:7.9.1
COPY kibana-docker /usr/local/bin/kibana-docker
COPY canvas.ndjson   /usr/local/bin/canvas.ndjson
CMD ["/usr/local/bin/kibana-docker"]

And finally include my logic inside the init script but before the exec instruction:

response="500"
while [ $response != "200" ]
do

sleep 20
response=$(curl -so /dev/null -w "%{http_code}\n" localhost:5601/status) 
if [ $response = "200" ]
then
curl -X POST localhost:5601/api/saved_objects/_import -H "kbn-xsrf: true" --form file=@/usr/local/bin/canvas.ndjson
fi

done &
exec /usr/share/kibana/bin/kibana --cpu.cgroup.path.override=/ --cpuacct.cgroup.path.override=/ ${longopts} "$@"
1 Like

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