37 lines
968 B
Bash
37 lines
968 B
Bash
#!/bin/bash
|
|
|
|
KEYSPACE="dev_keyspace"
|
|
|
|
# Start Cassandra in the background
|
|
cassandra -R &
|
|
|
|
# Wait for Cassandra to be ready
|
|
echo "Waiting for Cassandra to start..."
|
|
until cqlsh -e "SHOW HOST" > /dev/null 2>&1; do
|
|
sleep 2
|
|
done
|
|
|
|
if [ "$PRIMARY_NODE" = "true" ]; then
|
|
# Check if the keyspace exists
|
|
echo "Checking if keyspace $KEYSPACE exists..."
|
|
if ! cqlsh -e "DESCRIBE KEYSPACE $KEYSPACE;" > /dev/null 2>&1; then
|
|
echo "Keyspace $KEYSPACE does not exist. Creating keyspace and tables..."
|
|
cqlsh -f /docker-entrypoint-initdb.d/dev_keyspace_schema.cql
|
|
else
|
|
echo "Keyspace $KEYSPACE already exists. Skipping creation."
|
|
fi
|
|
fi
|
|
|
|
# Copy snapshots to the Cassandra data directory
|
|
echo "Copying snapshots..."
|
|
cp -r $DUMP_DIR/* /var/lib/cassandra/data/
|
|
|
|
# Import snapshots into the Cassandra data directory
|
|
echo "Importing snapshots..."
|
|
for table in $(ls $DUMP_DIR); do
|
|
nodetool import $KEYSPACE $table
|
|
done
|
|
|
|
# Keep the container running
|
|
tail -f /dev/null
|