blob: e46dea9fa96d14ece447f9cc0b4f419a01450b66 [file] [log] [blame]
Kishore Reddy, Gujja (kg811t)4ee89672018-03-20 17:15:25 -04001#!/bin/bash
2set -e
3
4# first arg is `-f` or `--some-option`
5# or there are no args
6if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
7 set -- cassandra -f "$@"
8fi
9
10# allow the container to be started with `--user`
11if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
12 chown -R cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_CONFIG"
13 exec gosu cassandra "$BASH_SOURCE" "$@"
14fi
15
16if [ "$1" = 'cassandra' ]; then
17 : ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}
18
19 : ${CASSANDRA_LISTEN_ADDRESS='auto'}
20 if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
21 CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
22 fi
23
24 : ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}
25
26 if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
27 CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
28 fi
29 : ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}
30
31 if [ -n "${CASSANDRA_NAME:+1}" ]; then
32 : ${CASSANDRA_SEEDS:="cassandra"}
33 fi
34 : ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}
35
36 sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"
37
38 for yaml in \
39 broadcast_address \
40 broadcast_rpc_address \
41 cluster_name \
42 endpoint_snitch \
43 listen_address \
44 num_tokens \
45 rpc_address \
46 start_rpc \
47 ; do
48 var="CASSANDRA_${yaml^^}"
49 val="${!var}"
50 if [ "$val" ]; then
51 sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
52 fi
53 done
54
55 for rackdc in dc rack; do
56 var="CASSANDRA_${rackdc^^}"
57 val="${!var}"
58 if [ "$val" ]; then
59 sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
60 fi
61 done
62fi
63echo "################################ Let run Scripts ##############################"
64for f in /docker-entrypoint-initdb.d/*; do
65 case "$f" in
66 *.cql) echo "$0: running $f" && until cqlsh -u cassandra -p cassandra -f "$f"; do >&2 echo "Cassandra is unavailable - sleeping"; sleep 2; done & ;;
67 *) echo "$0: ignoring $f" ;;
68 esac
69 echo
70done
71echo "################################ Let run Scripts End ##############################"
72
73exec "$@"