Skip to content

Instantly share code, notes, and snippets.

@iotaweb
Last active February 14, 2016 00:59
Show Gist options
  • Select an option

  • Save iotaweb/6137662 to your computer and use it in GitHub Desktop.

Select an option

Save iotaweb/6137662 to your computer and use it in GitHub Desktop.

Revisions

  1. iotaweb revised this gist Aug 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion riak.sh
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ for node in $(seq 1 $CLUSTER_SIZE)

    #echo "Building the cluster"
    # AUTOMATED JOINING NOT WORKING
    # The followign commented section will join nodes to cluster,
    # 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)
  2. iotaweb revised this gist Aug 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion riak.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    CWD=$(cd $(dirname $0); pwd)

    echo "This script will create a local riak cluster for development purposes only."
    echo "Prerequisites: install riak using homebrew (v1.3.1)."
    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"

  3. iotaweb revised this gist Aug 2, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions riak.sh
    Original file line number Diff line number Diff line change
    @@ -105,7 +105,8 @@ 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 2 3; do
    echo " ${NODE_NAME}${node}@127.0.0.1"
    done
    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"
  4. iotaweb renamed this gist Aug 2, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. iotaweb created this gist Aug 2, 2013.
    111 changes: 111 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,111 @@
    #!/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 (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 followign 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}1@127.0.0.1
    # 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 2 3; do
    echo " ${NODE_NAME}${node}@127.0.0.1"
    done
    echo "\nRiak cluster available here: http://127.0.0.1:8091/riak \n"