How to check that Cassandra is ready

五迷三道 提交于 2020-07-15 06:59:40

问题


I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready :

while ! nc -z localhost 7199; do
    sleep 1
done
echo "Cassandra is ready"
cqlsh -f ./createTables.cql

But the port is opened before the database is really ready, and the cqlsh therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance.


回答1:


First you need to wait on another port - 9042 - this is a port that is used by CQLSH.

Another approach could be also waiting for execution of sqlsh instead of nc (or as a second step, because nc is much faster to execute). For example, you can use something like commands:

while ! cqlsh -e 'describe cluster' ; do
    sleep 1
done

to wait until Cassandra is ready...



来源:https://stackoverflow.com/questions/48034869/how-to-check-that-cassandra-is-ready

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!