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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With