Skip to content

Instantly share code, notes, and snippets.

@jtuple
Created October 5, 2011 22:16
Show Gist options
  • Save jtuple/1265905 to your computer and use it in GitHub Desktop.
Save jtuple/1265905 to your computer and use it in GitHub Desktop.
require 'fog'
def start_server
Fog::Compute[:aws].servers.bootstrap(
:provider => "AWS",
# EBS-backed
# :image_id => "ami-63be790a"
# Ephermal
:image_id => "ami-fbbf7892",
:availability_zone => "us-east-1b",
:flavor_id => "m1.large",
# :flavor_id => "m1.xlarge",
:key_name => "my_fog",
:private_key_path => "~/.ssh/my_fog.pem",
:username => "ubuntu",
# Security group that allows SSH + all TCP/UDP within security group
:groups => ["mydefault"]
)
end
num=3
servers = Array.new(num)
# Launch nodes
num.times do |i|
puts "Launching server #{i}"
servers[i] = start_server()
end
# Setup riak + join
num.times do |i|
server = servers[i]
puts "server #{i}: waiting"
server.wait_for { ready? }
puts "server #{i}: downloading riak package"
server.ssh("wget http://downloads.basho.com/riak/riak-1.0.0/riak_1.0.0-1_amd64.deb")
server.scp("reip.sh", "reip.sh")
puts "server #{i}: setting up + launching riak"
server.ssh("sudo dpkg -i riak_1.0.0-1_amd64.deb")
server.ssh("sudo sh reip.sh #{server.private_ip_address}")
server.ssh("sudo riak start")
if(i > 0)
first = "riak@#{servers[0].private_ip_address}"
puts "server #{i}: joining to #{first}"
server.ssh("sudo riak-admin join #{first}")
end
end
puts "To login:"
servers.each do |server|
puts "ssh -i ~/.ssh/my_fog.pem ubuntu@#{server.dns_name}"
end
@jtuple
Copy link
Author

jtuple commented Oct 5, 2011

reip.sh

IP=$1
FILE=app.config
mv /etc/riak/${FILE} /etc/riak/${FILE}.old; sed s/127.0.0.1/${IP}/ /etc/riak/${FILE}.old > /etc/riak/${FILE}

FILE=vm.args
mv /etc/riak/${FILE} /etc/riak/${FILE}.old; sed s/127.0.0.1/${IP}/ /etc/riak/${FILE}.old > /etc/riak/${FILE}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment