# Script after kibana initialization

**URL:** <https://discuss.elastic.co/t/script-after-kibana-initialization/255722>\
**Category:** Kibana\
**Created:** [November 17, 2020, 3:00pm UTC](https://discuss.elastic.co/t/script-after-kibana-initialization/255722 "2020-11-17T15:00:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_Fernando\_Palm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_fernando_palm/32/77804_2.png) [@Carlos\_Fernando\_Palm](https://discuss.elastic.co/u/Carlos_Fernando_Palm)\
**Post date:** [November 17, 2020, 3:00pm UTC](https://discuss.elastic.co/t/script-after-kibana-initialization/255722/1 "2020-11-17T15:00:37Z")

</div>

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:

```auto
#!/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:

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

```

And I call this from docker-compose.yml:

```auto
 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)

---

<div class="post-metadata">

**Author:** ![Carlos\_Fernando\_Palm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_fernando_palm/32/77804_2.png) [@Carlos\_Fernando\_Palm](https://discuss.elastic.co/u/Carlos_Fernando_Palm)\
**Post date:** [November 18, 2020, 4:21pm UTC](https://discuss.elastic.co/t/script-after-kibana-initialization/255722/2 "2020-11-18T16:21:12Z")

</div>

OK, what I did was the following:

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

```auto
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:

```auto
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:

```auto
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} "$@"

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 16, 2020, 4:21pm UTC](https://discuss.elastic.co/t/script-after-kibana-initialization/255722/3 "2020-12-16T16:21:14Z")

</div>

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