Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check that Cassandra is ready

Tags:

cassandra

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.

like image 849
MeanStreet Avatar asked Dec 30 '17 14:12

MeanStreet


1 Answers

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...

like image 200
Alex Ott Avatar answered Oct 07 '22 03:10

Alex Ott