-
-
Save johndalton/9213047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This file should be in .../cookbooks/database/templates/default/database.yml.erb | |
# | |
<%= @environment %>: | |
adapter: <%= @adapter %> | |
database: <%= @database %> | |
username: <%= @username %> | |
password: <%= @password %> | |
host: <%= @host %> | |
reconnect: true | |
# This produces a block for each slave, named "slave", "slave_1", "slave_2", etc. | |
<% @slaves.each_with_index do |slave,i| %> | |
<%= i == 0 ? "slave" : "slave_#{i}" %>: | |
slavename: <%= slave["name"].nil? ? "---" : "'"+slave["name"]+"'" %> | |
adapter: <%= @adapter %> | |
database: '<%= @dbname %>' | |
username: '<%= @dbuser %>' | |
password: '<%= @dbpass %>' | |
host: '<%= slave['private_hostname'] %>' | |
reconnect: true | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name: database | |
# Recipe: default | |
# | |
# Description: | |
# Configure application servers to use mysql2 adapter for the database.yml config. | |
# All parameters except the adapter are pulled from the EY node JSON element. See | |
# http://docs.engineyard.com/use-deploy-hooks-with-engine-yard-cloud.html for an | |
# example of the node JSON object. This object is also used for by deploy hooks | |
# at Engine Yard. | |
# | |
# This file should be in .../cookbooks/database/recipes/default.rb | |
# | |
# | |
# Q: Why might we need this custom recipe? | |
# | |
# A: You may need to generate a custom database.yml file because Engine Yard's | |
# default database.yml file generator always generates a config file that uses the | |
# mysql adapter for Rails 2 apps. (For rails[34] apps in MySQL environents it | |
# attempts to detect whether the mysql or mysql2 gem is in use.) | |
# | |
# This recipes forces the mysql2 adapter for an existing Rails 2 app. | |
# | |
# The default database.yml lists any DB replicas in an environment, but some gems | |
# which distribute reads may require a custom syntax - in such cases the template | |
# can be modified to produce the appropriate syntax. | |
# | |
if ['solo', 'app_master', 'app', 'util'].include?(node[:instance_role]) | |
# for each application | |
node[:engineyard][:environment][:apps].each do |app| | |
# create new database.yml | |
template "/data/#{app[:name]}/shared/config/database.yml" do | |
source 'database.yml.erb' | |
owner node[:users][0][:username] | |
group node[:users][0][:username] | |
mode 0644 | |
variables({ | |
:environment => node[:environment][:framework_env], | |
:adapter => 'mysql2', | |
:database => app[:database_name], | |
:username => node[:users][0][:username], | |
:password => node[:users][0][:password], | |
:host => node[:db_host] | |
:slaves => node.environment.instances.select{|i| i["role"] =="db_slave"}, | |
}) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment