Skip to content

Commit

Permalink
added auto-generation of mongoid.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ines Sombra committed Apr 13, 2012
1 parent 6428cd7 commit 9f47261
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
1 change: 0 additions & 1 deletion cookbooks/mongodb/README.md
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions cookbooks/mongodb/recipes/app.rb
Expand Up @@ -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
49 changes: 13 additions & 36 deletions 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 -%>

0 comments on commit 9f47261

Please sign in to comment.