Permalink
Browse files

blerg

  • Loading branch information...
1 parent d213b54 commit 280c31bc1969b38e35cac5fd8f83f7094abc8b78 Ines Sombra committed Jan 6, 2012
@@ -1,21 +1,25 @@
-mongo_version("2.0.0")
+mongo_version("2.0.2")
mongo_name("mongodb-linux-#{@attribute["kernel"]["machine"]}-#{@attribute["mongo_version"]}")
mongo_path("/opt/mongodb-linux-#{@attribute["kernel"]["machine"]}-#{@attribute["mongo_version"]}")
mongo_base("/data/mongodb")
mongo_port("27017")
mongo_utility_instances( @attribute["utility_instances"].select { |ui| ui["name"].match(/mongodb/) } )
mongo_command("#{@attribute['mongo_path']}/bin/mongo")
+mongo_journaling ( true )
+mongo_secondary_instances( false )
if @attribute["utility_instances"].empty? || mongo_utility_instances.empty?
# We have detected no utility instances, so we are skipping the logic for this portion of the recipe.
else
# Chef::Log.info "mongo_utility_instances: #{@attribute["utility_instances"].inspect()}"
-
if mongo_utility_instances[0]["name"].match(/repl/)
mongo_replset ( mongo_utility_instances[1]["name"].sub("mongodb_","").sub("repl","").split("_")[0] )
else
mongo_replset( false )
end
+ #save array of secondary instances
+ #
+ # mongo_secondary_instances
+
end
-mongo_journaling ( true )
@@ -9,6 +9,13 @@
mongo_log = @node[:mongo_base] + "/log"
end
+mongo_bin_path = @node[:mongo_path] + "/bin"
+
+execute "expand path to include mongo instalation path" do
+ command "export PATH=\"$PATH\:#{mongo_bin_path}\""
+ not_if "echo $PATH | grep mongo"
+end
+
directory mongo_data do
owner user[:username]
group user[:username]
@@ -50,6 +57,7 @@
:ip => "0.0.0.0",
:port => @node[:mongo_port],
:extra_opts => [] }
+
if @node[:mongo_journaling]
mongodb_options[:extra_opts] << "--journal"
end
@@ -77,26 +85,28 @@
action :create
end
-#drop backup yml
+#---- drop backup yml
template "/etc/.mongodb.backups.yml" do
owner "root"
group "root"
mode 0600
source "mongodb.backups.yml.erb"
variables(:config => {
- :keep => node[:backup_window] || 14,
- :aws_secret_id => node[:aws_secret_id],
- :aws_secret_key => node[:aws_secret_key],
- :env => node[:environment][:name],
- :databases => {},
- :dbuser => nil, # not implemented
- :dbpass => nil, # not implemented
+ :dbuser => nil, # not implemented
+ :dbpass => nil, # not implemented
+ :keep => node[:backup_window] || 14,
+ :id => node[:aws_secret_id],
+ :key => node[:aws_secret_key],
+ :env => node[:environment][:name],
+ :region => node.engineyard.environment.region,
+ :backup_bucket => node.engineyard.environment.backup_bucket,
+ :databases => {} #do something here so it backs up the entire thing
})
end
-# Know how to snapshot itself
-Chef::Log.info "Redefine snapshots for Mongo"
+#------ teach it how to snapshot itself
+# Chef::Log.info "Redefine snapshots for Mongo"
partition = "data"
service_name = "mongo"
dbpath = "/#{partition}/mongodb/#{service_name}/"
@@ -18,6 +18,7 @@
require_recipe "mongodb::install"
require_recipe "mongodb::configure"
require_recipe "mongodb::start"
+ require_recipe "mongodb::eybackup"
if @node[:mongo_replset]
require_recipe "mongodb::replset"
end
@@ -8,9 +8,12 @@
if @node[:mongo_replset]
mongo_nodes = @node[:utility_instances].select { |instance| instance[:name].match(/^mongodb_repl#{@node[:mongodb_replset]}/) }
- if @node[:name].match(/_1$/)
+ # Chef::Log.info "Setting up Replica set: #{node[:mongo_replset]} \n mongo_nodes: #{mongo_nodes.inspect} \n executing on node #{@node[:name]}"
+
+ if (@node[:name].match(/_1$/) && (mongo_nodes.length == 3 || (mongo_nodes.length ==2 && mongo_arbiter.length > 3)))
+ # Chef::Log.info "Found first member of RS in #{@node[:name]}"
setup_js = "#{node[:mongo_base]}/setup_replset.js"
-
+
template setup_js do
source "setup_replset.js.erb"
owner user[:username]
@@ -23,15 +26,36 @@
})
end
+ #----- wait for set members to be up and initialize -----
+ # mongo_nodes.each do |mongo_node|
+ # ruby_block "wait for set members to come up" do
+ #
+ # times = 1000
+ # (1..times).each do |iter|
+ # if command "echo 'exit' | #{@node[:mongo_path]}/bin/mongo #{mongo_node[:hostname]}:#{@node[:mongo_port]}/local --quiet;"
+ # Chef::Log.info "woot! set member #{mongo_node[:hostname]} found alive"
+ # break
+ # else
+ # sleep 1
+ # end
+ # end
+ # Chef::Log.info "Set member #{mongo_node[:hostname]} not found"
+ # end
+ # end
+
mongo_nodes.each do |mongo_node|
execute "wait for mongo on #{mongo_node[:hostname]} to come up" do
command "until echo 'exit' | #{@node[:mongo_path]}/bin/mongo #{mongo_node[:hostname]}:#{@node[:mongo_port]}/local --quiet; do sleep 10s; done"
end
end
-
+ # ----- configure the set
execute "setup replset #{@node[:mongo_replset]}" do
command "#{@node[:mongo_path]}/bin/mongo local #{setup_js}"
only_if "echo 'rs.status()' | #{@node[:mongo_path]}/bin/mongo local --quiet | grep -q 'run rs.initiate'"
+ Chef::Log.info "Replica set node initialized"
end
+
+ else
+ Chef::Log.info "Not first node in replica or not enough set members defined, skipping set configuration"
end
end

0 comments on commit 280c31b

Please sign in to comment.