Blob Blame History Raw
#!/bin/bash

set -o pipefail

echo "Initializing..."

source ${CONTAINER_SCRIPTS_PATH}/common.sh

save_env_config_vars

if is_authorization_on; then
    echo "Authorization already enabled for this container, not setting new admin password..."
elif test "$(ls -A "$HOME/data" 2> /dev/null)"; then
    # If the container is using a not empty provided volume *and* authorization if turned off,
    # don't try to set a new CASSANDRA_ADMIN_PASSWORD, just enable authorization
    echo "Using a populated data directory, CASSANDRA_ADMIN_PASSWORD already set"
    turn_authorization_on
    set_password_authenticator
else
    if [ "$CASSANDRA_ADMIN_PASSWORD" ]; then
        create_admin_user
        turn_authorization_on
        # so far this is not working because cassandra-env.sh file is not modifiable (sits in scripts directory)
        #  turn_on_jmx_authentication
        # makes the admin password mandatory
    else
        usage "CASSANDRA_ADMIN_PASSWORD has to be set"
    fi
fi

exec cassandra -f -R