Last active
February 14, 2016 00:59
-
-
Save iotaweb/6137662 to your computer and use it in GitHub Desktop.
Script to create a local Riak cluster on Mac OS X.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CWD=$(cd $(dirname $0); pwd) | |
echo "This script will create a local riak cluster for development purposes only." | |
echo "Prerequisites: install riak using homebrew (tested with v1.3.1)." | |
echo "The cluster will be created in the current directory." | |
echo "Riak admin is enabled with no security.\n" | |
read -p "Enter a name for your cluster [cluster]: " name | |
CLUSTER_DIR=${name:-cluster} | |
read -p "Enter a prefix for each node [node]: " name | |
NODE_NAME=${name:-node} | |
read -p "Enter how many nodes you want [3]: " size | |
CLUSTER_SIZE=${size:-3} | |
BASE_DIR="${CWD}/${CLUSTER_DIR}" | |
echo "Creating cluster directory ${BASE_DIR}" | |
mkdir "${BASE_DIR}" | |
for node in $(seq 1 $CLUSTER_SIZE) | |
do | |
NODE_DIR="$BASE_DIR/${NODE_NAME}${node}" | |
echo "Creating node ${NODE_NAME}${node}" | |
cp -r $(brew --prefix riak) $NODE_DIR | |
echo " Removing data dir" | |
rm -rf "$NODE_DIR/libexec/data/" | |
HTTP="809${node}" | |
echo " Setting 'http' to '${HTTP}'" | |
perl -p -i.bak -e 's/({http, \[ {"\d+\.\d+\.\d+\.\d+", )(\d+)( } ]})/${1}'${HTTP}'${3}/g' "$NODE_DIR/libexec/etc/app.config" | |
HANDOFF_PORT="810${node}" | |
echo " Setting 'handoff_port' to '${HANDOFF_PORT}'" | |
perl -p -i.bak -e 's/({handoff_port, )(\d+)( })/${1}'${HANDOFF_PORT}'${3}/g' "$NODE_DIR/libexec/etc/app.config" | |
PB_PORT="808${node}" | |
echo " Setting 'pb_port' to '${PB_PORT}'" | |
perl -p -i.bak -e 's/({pb_port, )(\d+)( })/${1}'${PB_PORT}'${3}/g' "$NODE_DIR/libexec/etc/app.config" | |
if [ ${node} -eq 1 ] | |
then | |
echo " Setting 'riak control' admin settings" | |
echo " Enabling 'riak control' admin" | |
perl -p -i.bak -e 's/{enabled, false}/{enabled, true}/g' "$NODE_DIR/libexec/etc/app.config" | |
echo " Disabling authentication for 'riak control' admin" | |
perl -p -i.bak -e 's/{auth, userlist}/{auth, none}/g' "$NODE_DIR/libexec/etc/app.config" | |
fi | |
NAME="${NODE_NAME}${node}" | |
echo " Setting 'name' to '${NAME}'" | |
perl -p -i.bak -e 's/(-name )(\S+)(@.*)$/${1}'${NAME}'${3}/g' "$NODE_DIR/libexec/etc/vm.args" | |
NODE_BIN_DIR="$NODE_DIR/libexec/bin" | |
echo " Setting 'RUNNER_SCRIPT_DIR' to '${NODE_BIN_DIR}'" | |
perl -p -i.bak -e "s|RUNNER_SCRIPT_DIR=.*$|RUNNER_SCRIPT_DIR=${NODE_BIN_DIR}|g" "$NODE_DIR/bin/riak" \ | |
"$NODE_DIR/bin/riak-admin" \ | |
"$NODE_DIR/bin/search-cmd" \ | |
"$NODE_DIR/libexec/bin/riak" \ | |
"$NODE_DIR/libexec/bin/riak-admin" \ | |
"$NODE_DIR/libexec/bin/search-cmd" | |
done | |
for node in $(seq 1 $CLUSTER_SIZE) | |
do | |
echo "Starting node ${NODE_NAME}${node}" | |
${CLUSTER_DIR}/${NODE_NAME}${node}/bin/riak start | |
echo " Node ${NODE_NAME}${node} started" | |
echo " Pinging node ${NODE_NAME}${node}..." | |
${CLUSTER_DIR}/${NODE_NAME}${node}/bin/riak ping | |
done | |
#echo "Building the cluster" | |
# AUTOMATED JOINING NOT WORKING | |
# The following commented section will join nodes to cluster, | |
# but the partitions won't resize for some reason | |
#for node in $(seq 2 $CLUSTER_SIZE) | |
# do | |
# echo " Joining node ${NODE_NAME}${node}" | |
# ${CLUSTER_DIR}/${NODE_NAME}${node}/bin/riak-admin cluster join ${NODE_NAME}[email protected] | |
# done | |
#echo "Reviewing the staged plan..." | |
#${CLUSTER_DIR}/${NODE_NAME}1/bin/riak-admin cluster plan | |
#echo "Committing the staged plan..." | |
#${CLUSTER_DIR}/${NODE_NAME}1/bin/riak-admin cluster commit | |
echo "\nYou can further customise '${NODE_NAME}1/libexec/etc/app.config' \n" | |
echo "Example commands:\n" | |
echo " ${CLUSTER_DIR}/${NODE_NAME}1/bin/riak start" | |
echo " ${CLUSTER_DIR}/${NODE_NAME}1/bin/riak ping" | |
echo " ${CLUSTER_DIR}/${NODE_NAME}1/bin/riak stop \n" | |
echo "Riak admin control available here: http://127.0.0.1:8091/admin \n" | |
echo "Manually add the other nodes to your cluster, e.g.: \n" | |
for node in $(seq 2 $CLUSTER_SIZE) | |
do | |
echo " ${NODE_NAME}${node}@127.0.0.1" | |
done | |
echo "\nRiak cluster available here: http://127.0.0.1:8091/riak \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Riak 2.x requires
app.config
andvm.args
to be changed toriak.conf
for this script to work.