Permalink
Browse files

no longer use search for pairing, explicitly set the other machine to…

… partner with
  • Loading branch information...
1 parent 4d8b9f7 commit ed935c90bf428517711733da617a07622d5e5dc3 @mattray mattray committed Sep 30, 2011
View
@@ -8,7 +8,7 @@ Requirements
============
Platform
--------
-Tested with Ubuntu 10.10. You must have the 'linux-server' package and 'linux-headers-server' kernel installed to properly support the drbd module.
+Tested with Ubuntu 10.04 and 10.10. You must have the 'linux-server' package and 'linux-headers-server' kernel installed to properly support the drbd module.
Recipes
=======
@@ -18,15 +18,16 @@ Installs drbd but does no configuration.
default
-------
-Given a filesystem and a partner host, configures block replication between the hosts. The master will claim the primary, format the filesystem and mount the partition. The slave will simply mirror without mounting. It currently takes 2 chef-client runs to ensure the pair is synced properly.
+Given a filesystem and a partner host, configures block replication between the hosts. The master will claim the primary, format the filesystem and mount the partition. The slave will simply mirror without mounting. **It currently takes 2 chef-client runs to ensure the pair is synced properly.**
Attributes
==========
-The primary attributes of interest are
+The required attributes are
+* `node['drbd]['remote_host']` - Remote host to pair with.
* `node['drbd]['disk']` - Disk partition to mirror.
-* `node['drbd]['fs_type']` - Disk format for the mirrored disk.
* `node['drbd]['mount']` - Mount point to mirror.
+* `node['drbd]['fs_type']` - Disk format for the mirrored disk, defaults to `ext3`.
* `node['drbd]['master']` - Whether this node is master between the pair, defaults to `false`.
Roles
@@ -1,8 +1,8 @@
default[:drbd][:remote_host] = nil
-default[:drbd][:remote_ip] = nil
default[:drbd][:disk] = nil
-default[:drbd][:fs_type] = nil
default[:drbd][:mount] = nil
+default[:drbd][:fs_type] = "ext3"
default[:drbd][:dev] = "/dev/drbd0"
default[:drbd][:master] = false
default[:drbd][:port] = 7789
+default[:drbd][:configured] = false
@@ -3,6 +3,7 @@
override_attributes(
"drbd" => {
+ "remote_host" => "ubuntu2-1004.vm",
"disk" => "/dev/sdb1",
"fs_type" => "xfs",
"mount" => "/shared",
@@ -3,6 +3,7 @@
override_attributes(
"drbd" => {
+ "remote_host" => "ubuntu1-1004.vm",
"disk" => "/dev/sdb1",
"fs_type" => "xfs",
"mount" => "/shared"
View
@@ -22,72 +22,70 @@
include_recipe "drbd"
-#if remote host is blank, search for partner
+resource = "pair"
+
if node['drbd']['remote_host'].nil?
- remotes = search(:node, 'drbd:*') || []
- masters = 0
- remotes.each do |remote|
- masters += 1 if remote['drbd']['master']
- unless node.name.eql?(remote.name)
- Chef::Log.info "drbd::pair found #{remote.name}"
- node['drbd']['remote_host'] = remote.name
- node['drbd']['remote_ip'] = remote.ipaddress
- end
- end
- if (masters > 1)
- Chef::Application.fatal! "You may not have more than 1 master nodes for drbd."
- end
+ Chef::Application.fatal! "You must have a ['drbd']['remote_host'] defined to use the drbd::pair recipe."
end
-template "/etc/drbd.d/pair.res" do
+remote = search(:node, "name:#{node['drbd']['remote_host']}")[0]
+
+template "/etc/drbd.d/#{resource}.res" do
source "res.erb"
- variables( :mount => "pair" )
+ variables(
+ :resource => resource,
+ :remote_ip => remote.ipaddress
+ )
owner "root"
group "root"
- not_if { node['drbd']['remote_host'].nil? }
action :create
end
-first_pass = false
-
#first pass only, initialize drbd
-execute "drbdadm create-md pair" do
- subscribes :run, resources(:template => "/etc/drbd.d/pair.res")
+execute "drbdadm create-md #{resource}" do
+ subscribes :run, resources(:template => "/etc/drbd.d/#{resource}.res")
notifies :restart, resources(:service => "drbd"), :immediate
only_if do
cmd = Chef::ShellOut.new("drbd-overview")
overview = cmd.run_command
Chef::Log.info overview.stdout
overview.stdout.include?("drbd not loaded")
- first_pass = true
end
- not_if { node['drbd']['remote_host'].nil? }
action :nothing
end
#claim primary based off of node['drbd']['master']
execute "drbdadm -- --overwrite-data-of-peer primary all" do
- subscribes :run, resources(:execute => "drbdadm create-md pair")
- only_if { node['drbd']['master'] && !node['drbd']['remote_host'].nil? }
+ subscribes :run, resources(:execute => "drbdadm create-md #{resource}")
+ only_if { node['drbd']['master'] && !node['drbd']['configured'] }
action :nothing
end
#You may now create a filesystem on the device, use it as a raw block device
execute "mkfs -t #{node['drbd']['fs_type']} #{node['drbd']['dev']}" do
subscribes :run, resources(:execute => "drbdadm -- --overwrite-data-of-peer primary all")
- only_if { node['drbd']['master'] && !node['drbd']['remote_host'].nil? }
+ only_if { node['drbd']['master'] && !node['drbd']['configured'] }
action :nothing
end
directory node['drbd']['mount'] do
- only_if { node['drbd']['master'] && !node['drbd']['remote_host'].nil? }
+ only_if { node['drbd']['master'] && !node['drbd']['configured'] }
action :create
end
#mount -t xfs -o rw /dev/drbd0 /shared
mount node['drbd']['mount'] do
device node['drbd']['dev']
fstype node['drbd']['fs_type']
- only_if { node['drbd']['master'] && !node['drbd']['remote_host'].nil? && !first_pass}
+ only_if { node['drbd']['master'] && node['drbd']['configured'] }
action :mount
end
+
+#hack to get around the mount failing
+ruby_block "set drbd configured flag" do
+ block do
+ node['drbd']['configured'] = true
+ end
+ subscribes :create, resources(:execute => "mkfs -t #{node['drbd']['fs_type']} #{node['drbd']['dev']}")
+ action :nothing
+end
@@ -1,13 +1,13 @@
# Generated by Chef for <%= node[:fqdn] %>
-resource <%= @mount %> {
+resource <%= @resource %> {
device <%= node['drbd']['dev'] %>;
disk <%= node['drbd']['disk'] %>;
meta-disk internal;
on <%= node.name.split('.')[0] %> {
address <%= node.ipaddress %>:<%= node['drbd']['port'] %>;
}
on <%= node['drbd']['remote_host'].split('.')[0] %> {
- address <%= node['drbd']['remote_ip'] %>:<%= node['drbd']['port'] %>;
+ address <%= @remote_ip %>:<%= node['drbd']['port'] %>;
}
}

0 comments on commit ed935c9

Please sign in to comment.