Permalink
Browse files

updates/fixes for riaked

  • Loading branch information...
1 parent de9cb30 commit 35c31ef347e1e5fac466e954cd98c95cbd0fcffb @geemus committed Mar 25, 2011
Showing with 22 additions and 28 deletions.
  1. +22 −28 riaked.rb
View
50 riaked.rb 100644 → 100755
@@ -1,52 +1,46 @@
+#!/usr/bin/env ruby
+
require 'rubygems'
require 'fog'
require 'formatador'
-FLAVOR_ID = 1 # 256MB RAM, 10GB Storage
-IMAGE_ID = 49 # Ubuntu 10.04 LTS (Lucid Lynx)
-
-count = ARGV[0] && ARGV[0].to_i || 3
+# 256MB RAM, 10GB Storage, Ubuntu 10.04 LTS (Lucid Lynx)
+SERVER_ATTRIBUTES = {:flavor_id => 1, :image_id => 49}
# connect using rackspace credentials from default config in ~/.fog
compute = Fog::Compute.new(:provider => 'Rackspace')
-Thread.main[:ip_addresses] = []
-Thread.main[:servers] = []
-
-Formatador.display_line('bootstrapping server(s)')
+Thread.main[:ip_addresses], Thread.main[:servers] = [], []
+count = ARGV[0] && ARGV[0].to_i || 3
threads = []
-count.times do
+
+Formatador.display_lines(['', "bootstrapping #{count} nodes...", ''])
+count.times do |index|
threads << Thread.new do
- server = compute.servers.bootstrap(
- :flavor_id => FLAVOR_ID,
- :image_id => IMAGE_ID
- )
+ server = compute.servers.bootstrap(SERVER_ATTRIBUTES)
Thread.main[:servers] << server
Thread.main[:ip_addresses] << server.addresses['public'].first
-
- commands = [
+ server.ssh([
%{wget http://downloads.basho.com/riak/riak-0.14/riak_0.14.0-1_amd64.deb},
%{sudo dpkg -i riak_0.14.0-1_amd64.deb},
%{sed -i "s/127.0.0.1/#{Thread.main[:ip_addresses].last}/" /etc/riak/app.config},
%{sed -i "s/127.0.0.1/#{Thread.main[:ip_addresses].last}/" /etc/riak/vm.args},
%{riak start}
- ]
-
- unless Thread.main[:servers].length == 1
- commands << %{riak-admin join riak@#{Thread.main[:ip_addresses].first}}
- end
-
- server.ssh(commands)
+ ])
end
-end
+end
threads.each {|thread| thread.join}
-Formatador.display_line("ring_members => #{Thread.main[:ip_addresses].inspect}")
+Formatador.display_line("#{Thread.main[:ip_addresses].first} is joining cluster...")
+Thread.main[:servers][1..-1].each do |server|
+ Formatador.display_line("#{server.addresses['public'].first} is joining cluster...")
+ server.ssh(%{riak-admin join riak@#{Thread.main[:ip_addresses].first}})
+ server.wait_for { ssh(%{riak-admin ringready}).first.stdout =~ /TRUE/ }
+end
-Formatador.display_line('press enter to shutdown/cleanup')
+Formatador.display_lines(['', "Riaked! ring_members => #{Thread.main[:ip_addresses].inspect}"])
+Formatador.display_lines(['', "press enter to shutdown/cleanup"])
STDIN.getc
-Thread.main[:servers].each do |server|
- server.destroy
-end
+Thread.main[:servers].each {|server| server.destroy}

0 comments on commit 35c31ef

Please sign in to comment.