Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added auto-generation of mongoid.yml file

  • Loading branch information...
commit 9f472611ee314f08ae9f9ef13e4ba51e3072e833 1 parent 6428cd7
Ines Sombra authored
View
1  cookbooks/mongodb/README.md
@@ -53,7 +53,6 @@ Things (currently) lacking from this recipe:
* Ability to set up scheduled backups of your MongoDB database
* Ability to set up a sharded installation
- * Auto-generation of mongoid.yml files (coming soon)
* Arbiter support
Known Bugs
View
18 cookbooks/mongodb/recipes/app.rb
@@ -32,5 +32,23 @@
end
end
+
+ template "/data/#{mongo_app_name}/shared/config/mongoid.yml" do
+ source "mongoid.yml.erb"
+ owner user[:username]
+ group user[:username]
+ mode 0755
+
+ hosts = @node[:mongo_utility_instances].select { |instance| instance[:name].match(/#{mongo_app_name}/) }.map { |instance| [ instance[:hostname], @node[:mongo_port].to_i ] }
+ replica_set = @node[:mongo_utility_instances].any? { |instance| instance[:name].match(/^mongodb_repl/) }
+ if replica_set
+ hosts += @node[:mongo_utility_instances].select { |instance| instance[:name].match(/^mongodb_repl/) }.map { |instance| [ instance[:hostname], @node[:mongo_port].to_i ] }
+ end
+ variables(:environment => node[:environment][:framework_env],
+ :hosts => hosts,
+ :replica_set => replica_set,
+ :mongo_replsetname => node[:environment][:name] )
+ end
+
end
end
View
49 cookbooks/mongodb/templates/default/mongoid.yml.erb
@@ -1,36 +1,13 @@
-defaults: &defaults
-<% if @solo_server %>
- host: localhost
-<% else %>
- hosts:
-<% @mongo_nodes.each do |mongo_node| -%>
- - - <%=mongo_node[:hostname]%>
- <%=@mongo_port%>
-<% end -%>
- read_secondary: true
-
- development:
- <<: *defaults
- database: winealign_dev
-
- test:
- <<: *defaults
- database: winealign_staging
-
- production:
- <<: *defaults
- database: winealign_staging
-
- username: deploy
-
-
-<% end %>
-
-# If you use Sinatra (or anything other than rails) you need to do make a mongoid.yml like this:
-#
-# production:
-# hosts: [[db1.mongoid.org, 27017], [db2.mongoid.org, 27017]]
-# database: project_production
-# development:
-# hosts: [[db1.mongoid.org, 27017], [db2.mongoid.org, 27017]]
-# database: project_development
+<%= @environment %>:
+ database: <%=@mongo_replsetname%>
+ read_secondary: true
+ <% if @replica_set -%>
+ hosts:
+ <% @hosts.each do |host, port| -%>
+ - - <%= host %>
+ - <%= port %>
+ <% end -%>
+ <% else -%>
+ host: <%= @hosts[0][0] %>
+ port: <%= @hosts[0][1] %>
+ <% end -%>
Please sign in to comment.
Something went wrong with that request. Please try again.