Skip to content

Instantly share code, notes, and snippets.

# Runs a block multiple times, each time with a different alternative
# Intended for connection failover
# Inspired by http://github.com/carlo/retryable
module RetryWith
def retry_with(alternatives, options={}, &block)
opts = {:tries => alternatives.size, :on => Exception}.merge(options)
return if opts[:tries] == 0
#!/bin/bash
# chef install
sudo apt-get -q -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget >> /tmp/chef_bootstrap.log
cd /tmp
wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz
tar zxvf rubygems-1.3.2.tgz >> /tmp/chef_bootstrap.log
cd rubygems-1.3.2
sudo ruby setup.rb --no-ri --no-rdoc >> /tmp/chef_bootstrap.log
template "/etc/motd" do
source "motd.erb"
end
motd.erb:
Runlist: <%= @node[:run_list] %>
# try to attach any of the available volumes
aws_ebs_volume "#{datanode_dir}_#{node[:hadoop][:cluster_name]}" do
aws_access_key aws['aws_access_key_id']
aws_secret_access_key aws['aws_secret_access_key']
size node[:hadoop][:datanode][:ebs_vol_size]
device ebs_vol_dev
volume_ids available_volumes.collect { |v| v['volume_id'] }
action :attach_first
provider "aws_ebs_volume"
end
require 'rubygems'
require 'avro'
count = ARGV[0] ? ARGV[0].to_i : 10000
puts "writing #{count} records"
SCHEMA = <<-JSON
{ "type": "record",
"name": "User",
"fields" : [
# riddle/lib/riddle/client/response.rb
# Return the next integer value from the stream
def next_int
int = next_int_fast(@str, @marker)
@marker += 4
int
end
Date: Sat, 28 Aug 2010 08:00:03 +0000 (UTC)
From: Cron Daemon <root@ip-10-204-107-97.ec2.internal>
To: root@ip-10-204-107-97.ec2.internal
Subject: Cron <root@ip-10-204-107-97> chef-solo -j /etc/chef/chef-solo-database-snapshot.json -c /etc/chef/chef-solo-database-snapshot.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Setting the run_list to ["recipe[database::snapshot]"] from JSON
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Starting Chef Run (Version 0.9.8)
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Overriding duplicate definition pear_module, new found in /var/chef/cache/cookbooks/php/definitions/pear.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: Overriding duplicate definition pear_channel, new found in /var/chef/cache/cookbooks/php/definitions/pear_channel.rb
[Sat, 28 Aug 2010 08:00:03 +0000] INFO: mysql_database: flushing tables with read lock
#!/usr/bin/ruby
require 'rubygems'
require 'fileutils'
require 'chef'
pwd = File.dirname(__FILE__)
Chef::Config.from_file("/etc/chef/client.rb")
Chef::Config[:node_name] = ENV['OPSCODE_USER']
if node[:ec2][:ephemeral][:devices].include?("/dev/sdd")
# if we also have sdd and sde, raid0 them and put data there
data_raid_block_devs = [ "/dev/sdd", "/dev/sde" ]
data_raid_mountpoint = "/mnt/cassandra_data"
data_raid_dev = "/dev/md0"
data_file_dir = Array(node[:cassandra][:data_file_dirs]).first
package "mdadm" do
action :install
end
"map": "function(doc) { if (doc.type == 'lock') { emit(doc.message_id, null) } else { emit(doc._id, doc) } }",
"reduce": "function(keys, values, rereduce) { if (values.length == 1) return values[0] }"