Running a three node riak cluster using a homebrew installation

08 April 2012

If you're following The Riak Fast Track with a Homebrew-based riak installation, you won't be able to start up the three nodes as described without some fiddling, because the Makefile isn't included in the Homebrew installation.

If you already installed Erlang, the Riak installation is as simple as brew install riak.

To create the 4 nodes without the Makefile, you can run the following script. It makes 4 copies of our Homebrew-based Riak installation and adjusts their configuration and the hardcoded path in Riak's executable scripts:

#!/bin/bash

CWD=$(cd $(dirname $0); pwd)

BASE_DIR="${CWD}/dev"
echo "Creating dev directory ${BASE_DIR}"
mkdir "${BASE_DIR}"

for node in 1 2 3 4; do
  NODE_NAME="dev${node}"
  NODE_DIR="$BASE_DIR/$NODE_NAME"

  echo "Creating node ${NODE_NAME}"
  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"
  
  NAME="dev${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

Thanks to Brian Roach, who told me about the hardcoded path inside the executable scripts.

Getting JSLint to run on a Homebrew-based V8

04 April 2012

Douglas Crockford's JSLint is meant to be run inside a browser. During development, I'd prefer to run it via the command line, using Google's V8 JavaScript Engine (brew install v8).

Fortunately, the real work has already been done in jslint-v8 by Vladimir Dobriakov. We just have to figure out how to get the Rakefile to compile against our Homebrew-based V8 installation:

$ brew install v8
$ cd /tmp
$ git clone git://github.com/geekq/jslint-v8.git && cd jslint-v8
$ V8_BASEDIR=$(brew --prefix v8) rake
$ cp jslint ~/bin/

I really should make this a Homebrew formula, but I'll save that for another day.

Installing Erlang R14B04 on Mac OS X 10.7.3. "Lion" via homebrew

27 March 2012

While brew install erlang sounds easy enough, it won't give us what we need for 2 reasons:

To tackle the first problem, let's find out which versions of Erlang are available:

$ brew versions erlang
R15B     git checkout 12b8d77 /usr/local/Library/Formula/erlang.rb
R14B04   git checkout 8560672 /usr/local/Library/Formula/erlang.rb
R14B03   git checkout 9332ca9 /usr/local/Library/Formula/erlang.rb
R14B02   git checkout b782d9d /usr/local/Library/Formula/erlang.rb
...

In order to select R14B04, we just need to execute the provided command:

$ cd $(brew --prefix)
$ git checkout 8560672 /usr/local/Library/Formula/erlang.rb

(In case brew complains about a missing git repository, just run brew update and try again. This should only happen with new brew installations.)

brew info erlang should now list R14B04 as the selected version, but trying to install via brew install erlang will fail with compiler errors. The solution is to instruct brew to use gcc for compilation (instead of llvm-gcc or clang).
Unfortunately, gcc isn't available in Lion or the standard Homebrew formula repository. We therefore have to install it from Homebrew's dupes repository:

$ brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb

Now it's time to actually install Erlang using gcc (this may take a while):

$ brew -v install --use-gcc erlang

If all goes well, the Erlang shell should now work and show us it's running on Erlang R14B04:

$ erl
Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
...

Finally, we can now go on to install Rebar, an Erlang build tool. We need to provide the --HEAD option, since Rebar "is a head-only formula" (fortunately, brew is smart enough to tell you what to do about that in case you forgot):

$ brew -v install --HEAD rebar