Permalink
Browse files

Limited support for formatting disks.

  • Loading branch information...
1 parent 532a0b0 commit b697be1547864040415cf4a6c2250fcb11f404a2 @dvrensk committed Sep 7, 2010
Showing with 77 additions and 4 deletions.
  1. +5 −2 README.mdown
  2. +24 −0 contrib/chef-bootstrap.sh
  3. +38 −0 contrib/cookbooks/ec2-ebs/recipes/default.rb
  4. +10 −2 lib/awsborn/server.rb
View
@@ -65,7 +65,7 @@ Servers take five different directives:
* `image_id` -- a valid EC2 AMI. Specify `:sudo_user` as an option if the AMI
does not allow you to log in as root.
* `security_group` -- a security group that you own.
-* `keys` -- one or more globs to public ssh keys. When the servers are running,
+* `keys` -- one or more globs to public ssh key files. When the servers are running,
`root` will be able to log in using any one of these keys.
* `bootstrap_script` -- path to a script which will be run on each instance as
soon as it is started. Use it to bootstrap `chef` and let `chef` take it from
@@ -87,7 +87,9 @@ Mandatory keys:
* `:zone` -- the availability zone for the server. One of `:us_east_1a`, `:us_east_1b`,
`:us_east_1c`, `:us_west_1a`, `:us_west_1b`, `:eu_west_1a`, `:eu_west_1b`.
* `:disk` -- a hash of `device => volume-id`. Awsborn uses the disks to tell if a server
- is running or not (see *Launching a cluster*).
+ is running or not (see *Launching a cluster*). `volume-id` can also be an array
+ `[volume-id, :format]`, in which case `the_server.format_disk_on_device?(device)`
+ will return `true`. See `contrib/cookbooks/ec2-ebs` for example usage.
Optional keys:
@@ -209,6 +211,7 @@ Awsborn integrates with [Chef Solo](http://github.com/opscode/chef). An example
"ec2-ebs",
"git",
"gems",
+ "lumberjack"
]
}
end
View
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+echo '------------------'
+echo 'Bootstrapping Chef'
+echo
+
+aptitude -y update
+aptitude -y install gcc g++ curl build-essential \
+ libxml-ruby libxml2-dev \
+ ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby \
+ libruby libruby-extras libopenssl-ruby \
+ libdbm-ruby libdbi-ruby libdbd-sqlite3-ruby \
+ sqlite3 libsqlite3-dev libsqlite3-ruby
+
+curl -L 'http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz' | tar zxf -
+cd rubygems* && ruby setup.rb --no-ri --no-rdoc
+
+ln -sfv /usr/bin/gem1.8 /usr/bin/gem
+
+gem install chef ohai --no-ri --no-rdoc
+
+echo
+echo 'Bootstrapping Chef - done'
+echo '-------------------------'
@@ -0,0 +1,38 @@
+#
+# Cookbook Name:: ec2-ebs
+# Recipe:: default
+#
+# Assumes volumes are preformatted by YOU or specified as
+# # in cluster:
+# server :log_a, :zone => :eu_west_1a, :disk => {:sdf => ["vol-abcd1234", :format]}
+# # in chef_dna:
+# :ebs_volumes => [
+# {:device => "sdf", :path => "/apps", :format => format_disk_on_device?("sdf")}
+# ],
+
+
+for ebs_volume in (node["ebs_volumes"] || [])
+ if (`grep /dev/#{ebs_volume[:device]} /etc/fstab` == "")
+ while not File.exists?("/dev/#{ebs_volume[:device]}")
+ Chef::Log.info("EBS volume device /dev/#{ebs_volume[:device]} not ready...")
+ sleep 5
+ end
+
+ execute "format #{ebs_volume[:device]}" do
+ command "mkfs -t ext3 -F /dev/#{ebs_volume[:device]}"
+ only_if { ebs_volume[:format] }
+ end
+
+ directory ebs_volume[:path] do
+ owner 'root'
+ group 'root'
+ mode 0755
+ end
+
+ mount ebs_volume[:path] do
+ device "/dev/#{ebs_volume[:device]}"
+ fstype "ext3"
+ action [:mount, :enable]
+ end
+ end
+end
View
@@ -57,7 +57,7 @@ def logger
def running?
map = {}
- disk.values.each { |vol_id| map[vol_id] = ec2.instance_id_for_volume(vol_id) }
+ disk_volume_ids.each { |vol_id| map[vol_id] = ec2.instance_id_for_volume(vol_id) }
ids = map.values.uniq
if ids.size > 1
raise ServerError, "Volumes for #{self.class.name}:#{name} are connected to several instances: #{map.inspect}"
@@ -159,7 +159,8 @@ def bootstrap
def attach_volumes
logger.debug "Attaching volumes #{disk.values.join(', ')} to #{name}"
- disk.each_pair do |device, volume|
+ disk.each_pair do |device, str_or_ary|
+ volume = str_or_ary.is_a?(Array) ? str_or_ary.first : str_or_ary
device = "/dev/#{device}" if device.is_a?(Symbol) || ! device.match('/')
res = ec2.attach_volume(volume, device)
end
@@ -209,6 +210,13 @@ def zone
def disk
@options[:disk]
end
+ def disk_volume_ids
+ disk.values.map { |str_or_ary| str_or_ary.is_a?(Array) ? str_or_ary.first : str_or_ary }
+ end
+ def format_disk_on_device? (device)
+ volume = disk[device.to_sym]
+ volume.is_a?(Array) && volume.last == :format
+ end
def image_id
self.class.image_id
end

0 comments on commit b697be1

Please sign in to comment.