2
2
# vim: set tabstop=2 expandtab:
6
6
export LANG=en_US.UTF-8
9
IP=`unit-get private-address`
10
# Pull configuration for charm
11
JMX_PORT=`config-get jmx-port`
12
CLUSTER_PORT=`config-get cluster-port`
13
CLIENT_PORT=`config-get client-port`
14
CLUSTER_NAME=`config-get cluster-name`
16
8
# Install cassandra source and install packages
17
9
install_cassandra () {
18
10
juju-log "Installing Cassandra"
23
15
# Update the repositories
25
17
# Install the package
26
apt-get -qq install -y cassandra
18
apt-get -qq install -y cassandra python-cheetah
29
21
# Update the cassandra environment with the appropriate JMX port
30
22
configure_jmx_port () {
31
23
juju-log "Configuring JMX port"
32
sed -i -e "s/^JMX_PORT=.*/JMX_PORT=\"${1}\"/" /etc/cassandra/cassandra-env.sh
24
JMX_PORT=`config-get jmx-port`
25
sed -i -e "s/^JMX_PORT=.*/JMX_PORT=\"${JMX_PORT}\"/" /etc/cassandra/cassandra-env.sh
33
26
# Open port ready for expose
27
open-port ${JMX_PORT}/TCP
31
# Make sure that we use the resolvable private address
32
# dig deals with both hostnames and ip addresses in a nice
34
dig +short `unit-get private-address`
37
37
# Construct the cassandra.yaml file from the appropriate information above
38
38
configure_cassandra () {
39
39
juju-log "Configuring Cassandra"
41
CLUSTER_PORT=`config-get cluster-port`
42
CLIENT_PORT=`config-get client-port`
43
CLUSTER_NAME=`config-get cluster-name`
44
AUTO_MEMORY=`config-get auto-memory`
45
HEAP_SIZE=`config-get heap-size`
46
NEW_GEN_SIZE=`config-get new-gen-size`
40
47
# This needs to 'detect' whether its running in ec2
41
48
# and use the ec2Snitch instead if it is - or we could
42
49
# specify this as a configuration parameter
43
sed -i -e "s/^cluster_name:.*/cluster_name: \'${1}\'/" \
44
-e "s/\- seeds:.*/\- seeds: \"${2}\"/" \
45
-e "s/^storage_port:.*/storage_port: ${3}/" \
46
-e "s/^listen_address:.*/listen_address: ${2}/" \
47
-e "s/^rpc_address:.*/rpc_address: ${2}/" \
48
-e "s/^rpc_port:.*/rpc_port: ${4}/" \
50
sed -i -e "s/^cluster_name:.*/cluster_name: \'${CLUSTER_NAME}\'/" \
51
-e "s/\- seeds:.*/\- seeds: \"${IP}\"/" \
52
-e "s/^storage_port:.*/storage_port: ${CLUSTER_PORT}/" \
53
-e "s/^listen_address:.*/listen_address: ${IP}/" \
54
-e "s/^rpc_address:.*/rpc_address: ${IP}/" \
55
-e "s/^rpc_port:.*/rpc_port: ${CLIENT_PORT}/" \
49
56
/etc/cassandra/cassandra.yaml
50
57
# Open port ready for expose
58
open-port ${CLIENT_PORT}/TCP
60
# Configure memory settings as specified in configuration
61
if [ "$AUTO_MEMORY" = "False" ]; then
62
juju-log "Configuring Manual Memory Setttings"
63
sed -i -e "s/^[#]MAX_HEAP_SIZE=.*/MAX_HEAP_SIZE=\"${HEAP_SIZE}\"/" \
64
-e "s/^[#]HEAP_NEWSIZE=.*/HEAP_NEWSIZE=\"${NEW_GEN_SIZE}\"/" /etc/cassandra/cassandra-env.sh
66
sed -i -e "s/^[#]MAX_HEAP_SIZE=.*/#MAX_HEAP_SIZE=\"${HEAP_SIZE}\"/" \
67
-e "s/^[#]HEAP_NEWSIZE=.*/#HEAP_NEWSIZE=\"${NEW_GEN_SIZE}\"/" /etc/cassandra/cassandra-env.sh
54
71
# Service Control Commands
108
125
if [ -z "${AUTO}" ]; then
109
126
restart_cassandra
111
juju-log "$JUJU_REMOTE_UNIT modified its settings"
112
juju-log "Relation settings:"
114
juju-log Relation members:
128
juju-log "$JUJU_REMOTE_UNIT modified its settings or departed"
131
decommission_node () {
132
juju-log "Decommissioning node - this may take some time..."
133
nodetool -h `get_private_ip` decommission
118
136
# Actual processing
123
141
# Install cassandra first run only
124
142
[[ -d /usr/share/cassandra ]] || install_cassandra
125
143
# Update the cassandra environment with the appropriate JMX port
126
configure_jmx_port $JMX_PORT
127
145
# Construct the cassandra.yaml file from the appropriate information above
128
configure_cassandra "$CLUSTER_NAME" $IP $CLUSTER_PORT $CLIENT_PORT
129
147
# Restart as required
130
148
restart_cassandra
133
151
# Update the cassandra environment with the appropriate JMX port
134
configure_jmx_port $JMX_PORT
135
153
# Construct the cassandra.yaml file from the appropriate information above
136
configure_cassandra "$CLUSTER_NAME" $IP $CLUSTER_PORT $CLIENT_PORT
137
155
# Restart as required
138
156
restart_cassandra
149
167
database-relation-joined)
150
setup_database_interface $CLIENT_PORT
168
setup_database_interface
152
170
cluster-relation-joined)
153
171
juju-log "Joining cassandra cluster..."
155
cluster-relation-changed)
173
cluster-relation-changed|cluster-relation-departed)
156
174
reconfigure_cluster_seeds
158
176
jmx-relation-joined)
159
setup_jmx_interface $JMX_PORT
162
180
juju-log "Command not recognised"