Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryodaniel/702435b85267a5d09dee to your computer and use it in GitHub Desktop.
Save coryodaniel/702435b85267a5d09dee to your computer and use it in GitHub Desktop.
#
# 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 do we need this custom recipe?
#
# A: We needed to generate our own 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 and always uses the mysql2 adapter for Rails 3 apps.
#
# In our case we needed to use the mysql2 adapter with our existing Rails 2 app.
#
# Apps using a replicated DB setup on EY may also need a custom Chef recipe to
# generate a database.yml
#
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/keep.database.yml" do
source 'database.yml.erb'
owner node[:owner_name]
group node[:owner_name]
mode 0644
variables({
:environment => node[:environment][:framework_env],
:database => app[:database_name],
:username => node[:users][0][:username],
:password => node[:users][0][:password],
:host => node[:db_host],
:slaves => node[:db_slaves],
:adapter => 'mysql2',
:pool => 20
})
end
if File.exists?("/data/#{app[:name]}/shared/config/keep.database.yml") and File.exists?("/data/#{app[:name]}/shared/config/database.yml")
file "/data/#{app[:name]}/shared/config/database.yml" do
action :delete
end
end
link "/data/#{app[:name]}/shared/config/keep.database.yml" do
to "/data/#{app[:name]}/shared/config/database.yml"
end
end
end
@rbankston
Copy link

execute "remove database.yml" do
command "rm /data/#{app[:name]}/shared/config/database.yml"
not_if { FileTest.exists?("/data/#{app[:name]}/shared/config/keep.database.yml") }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment