A way to check Oracle finished sql

2019-01-29 11:55发布

I've got Docker Compose cluster and one of the containers is Oracle 12c. There is schema.sql file to initialize the db. I would like my application to wait until the db executes all the sql. How can I do it in an automatic fashion with bash?

Thank you very much for any suggestions!

1条回答
爷、活的狠高调
2楼-- · 2019-01-29 12:57

There's a lot to explain here, but I'll link one of my previous answers for a similar problem - steps are actually the same because only the database service and background differs.

1) First thing is, you have to provide a bash script that will wait until a service will respond via http. In databases it usually happens when DB is ready to go and all initializations are done.

the wait-for-it.sh script written by vishnubob in his wait-for-it repo @ github.

2) Second thing, you have to get that script inside each container that requires your DB.

3) Third, you specify a entrypoint in your compose file, that will execute the waiting script before the actual command running your service will trigger.

example of a entrypoint (as reference to the answer I link to)

docker-entrypoint.sh:

#!/bin/bash
set -e
sh -c './wait-for-it.sh oracle:3306 -t 30'
exec "$@"

All these steps are explained in detail here in scenario 2, be aware of a reference to my another answer inside the answer I'm pointing at here. This issue is a very common problem for beginners and takes quite a lot of explanation, so I cannot post it all here.

note here concerning depends_on which you might think is a native solution for this problem from docker - as docs state, it only waits until the container is running, not actually finished it's internal jobs - docker is not aware of how much there is to be done.

查看更多
登录 后发表回答