Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/sh
# No sudo, as init scripts run as root
BUCKET_NAME=$1
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
BIND_IP=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
echo "Bucket name for fetching configuration is $BUCKET_NAME"
echo "Current region is $REGION"
# First we need Java8 (Cassandra is not yet well tested with Java 9)
yum -y update
yum -y remove java
yum -y install java-1.8.0-openjdk
# Install cassandra
cat <<EOT >> /etc/yum.repos.d/cassandra.repo
[cassandra]
name=Apache Cassandra
baseurl=https://www.apache.org/dist/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.apache.org/dist/cassandra/KEYS
EOT
yum -y install cassandra
#TODO configure memory in /etc/cassandra/conf/jvm.options
# Copy configuration from S3
aws s3 cp s3://$BUCKET_NAME/cassandra.yaml.template /etc/cassandra/conf/cassandra.yaml
python /tmp/install/update-cassandra-cluster-config.py
service cassandra start
chkconfig cassandra on
while ! echo exit | nc $BIND_IP 9042; do sleep 10; done
cqlsh -e "CREATE KEYSPACE IF NOT EXISTS your_keyspace WITH REPLICATION = { 'class': 'NetworkTopologyStrategy', '$EC2_REGION': 3 } AND DURABLE_WRITES = true;" $BIND_IP 9042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment