Created
September 14, 2012 19:03
-
-
Save tyrauber/3723999 to your computer and use it in GitHub Desktop.
Riak cluster setup script
This file contains 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
### ruby riak.rb number_of_nodes | |
require "rubygems" | |
# `killall epmd` ## to kill running riaks | |
@riak_url = "http://s3.amazonaws.com/downloads.basho.com/riak/CURRENT/osx/10.4/" | |
@riak_filename = "riak-1.2.0-osx-x86_64.tar.gz" | |
@port = 8098 | |
def setup(nodes) | |
n = if !nodes.nil? then nodes else 4 end | |
create_nodes(n, @port) | |
create_cluster(n, @port) | |
end | |
def create_nodes(nodes, port) | |
file = download_riak | |
`mkdir riak` if !File.directory? "riak" | |
if Dir.glob("riak/*").count <= 2 | |
nodes.to_i.times.each_with_index do |i,n| | |
unzip_database | |
setup_riak_node(i) | |
end | |
`find . -name '*-e*' | xargs rm` | |
end | |
end | |
def create_cluster(nodes, port) | |
nodes.to_i.times.each_with_index do |i, n| | |
`riak/riak#{i+1}/bin/riak start` | |
`riak/riak#{i+1}/bin/riak ping` | |
`riak/riak#{i+1}/bin/riak-admin join [email protected]` if i !=0 | |
end | |
puts `riak/riak1/bin/riak-admin member_status` | |
end | |
def setup_riak_node(i) | |
path = ['riak/', @riak_filename.gsub("-osx-x86_64.tar.gz", "")] | |
`mv #{path.join("")} #{path[0]}#{path[1][0,4]}#{i+1}` | |
[8098,8099,8087].each do |p| | |
`sed -i-e 's/#{p.to_s}/#{(p+(i*100)).to_s}/' #{path[0]}#{path[1][0,4]}#{i+1}/etc/app.config` | |
end | |
`sed -i-e 's/{storage_backend, riak_kv_bitcask_backend}/{storage_backend, riak_kv_eleveldb_backend}/' #{path[0]}#{path[1][0,4]}#{i+1}/etc/app.config` | |
`sed -i-e 's/[email protected]/riak#{i+1}@127.0.0.1/' #{path[0]}#{path[1][0,4]}#{i+1}/etc/vm.args` | |
end | |
def download_riak | |
if Dir.glob("riak/riak*.tar.gz").empty? | |
`mkdir riak` if !File.directory? "riak" | |
puts "curl -o riak/#{@riak_filename} #{@riak_url}#{@riak_filename}" | |
`curl -o riak/#{@riak_filename} #{@riak_url}#{@riak_filename}` | |
puts "Downloaded #{@riak_filename} to riak" | |
end | |
end | |
def unzip_database | |
path = "riak/" | |
if File.exist?("#{path}#{@riak_filename}") | |
`gunzip -c #{path}#{@riak_filename} | tar xopf - -C #{path}` | |
end | |
end | |
if ARGV[0] | |
num_nodes = ARGV[0].to_i | |
else | |
num_nodes= 4 | |
end | |
setup(num_nodes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment