elzar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/.chef/knife.rb +3 -0
  2. data/.gitignore +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +11 -0
  5. data/Gemfile.lock +96 -0
  6. data/README.md +42 -0
  7. data/Rakefile +1 -0
  8. data/Vagrantfile +16 -0
  9. data/cookbooks/.gitkeep +0 -0
  10. data/cookbooks/apt/README.md +122 -0
  11. data/cookbooks/apt/files/default/apt-cacher +9 -0
  12. data/cookbooks/apt/files/default/apt-cacher.conf +144 -0
  13. data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
  14. data/cookbooks/apt/metadata.rb +13 -0
  15. data/cookbooks/apt/providers/repository.rb +73 -0
  16. data/cookbooks/apt/recipes/cacher-client.rb +44 -0
  17. data/cookbooks/apt/recipes/cacher.rb +45 -0
  18. data/cookbooks/apt/recipes/default.rb +50 -0
  19. data/cookbooks/apt/resources/repository.rb +30 -0
  20. data/cookbooks/build-essential/README.md +24 -0
  21. data/cookbooks/build-essential/metadata.rb +10 -0
  22. data/cookbooks/build-essential/recipes/default.rb +45 -0
  23. data/cookbooks/database/README.md +403 -0
  24. data/cookbooks/database/libraries/provider_database_mysql.rb +97 -0
  25. data/cookbooks/database/libraries/provider_database_mysql_user.rb +76 -0
  26. data/cookbooks/database/libraries/provider_database_postgresql.rb +126 -0
  27. data/cookbooks/database/libraries/provider_database_postgresql_user.rb +78 -0
  28. data/cookbooks/database/libraries/provider_database_sql_server.rb +109 -0
  29. data/cookbooks/database/libraries/provider_database_sql_server_user.rb +106 -0
  30. data/cookbooks/database/libraries/resource_database.rb +111 -0
  31. data/cookbooks/database/libraries/resource_database_user.rb +90 -0
  32. data/cookbooks/database/libraries/resource_mysql_database.rb +34 -0
  33. data/cookbooks/database/libraries/resource_mysql_database_user.rb +34 -0
  34. data/cookbooks/database/libraries/resource_postgresql_database.rb +35 -0
  35. data/cookbooks/database/libraries/resource_postgresql_database_user.rb +35 -0
  36. data/cookbooks/database/libraries/resource_sql_server_database.rb +34 -0
  37. data/cookbooks/database/libraries/resource_sql_server_database_user.rb +34 -0
  38. data/cookbooks/database/metadata.rb +21 -0
  39. data/cookbooks/database/recipes/default.rb +20 -0
  40. data/cookbooks/database/recipes/ebs_backup.rb +89 -0
  41. data/cookbooks/database/recipes/ebs_volume.rb +196 -0
  42. data/cookbooks/database/recipes/master.rb +78 -0
  43. data/cookbooks/database/recipes/snapshot.rb +62 -0
  44. data/cookbooks/database/templates/default/app_grants.sql.erb +8 -0
  45. data/cookbooks/database/templates/default/aws_config.erb +3 -0
  46. data/cookbooks/database/templates/default/chef-solo-database-snapshot.cron.erb +10 -0
  47. data/cookbooks/database/templates/default/chef-solo-database-snapshot.json.erb +1 -0
  48. data/cookbooks/database/templates/default/chef-solo-database-snapshot.rb.erb +6 -0
  49. data/cookbooks/database/templates/default/ebs-backup-cron.erb +2 -0
  50. data/cookbooks/database/templates/default/ebs-db-backup.sh.erb +8 -0
  51. data/cookbooks/database/templates/default/ebs-db-restore.sh.erb +10 -0
  52. data/cookbooks/database/templates/default/s3cfg.erb +27 -0
  53. data/cookbooks/mysql/README.md +148 -0
  54. data/cookbooks/mysql/attributes/server.rb +68 -0
  55. data/cookbooks/mysql/libraries/database.rb +19 -0
  56. data/cookbooks/mysql/libraries/helpers.rb +33 -0
  57. data/cookbooks/mysql/metadata.rb +90 -0
  58. data/cookbooks/mysql/recipes/client.rb +51 -0
  59. data/cookbooks/mysql/recipes/default.rb +20 -0
  60. data/cookbooks/mysql/recipes/server.rb +133 -0
  61. data/cookbooks/mysql/recipes/server_ec2.rb +49 -0
  62. data/cookbooks/mysql/templates/default/debian.cnf.erb +12 -0
  63. data/cookbooks/mysql/templates/default/grants.sql.erb +15 -0
  64. data/cookbooks/mysql/templates/default/my.cnf.erb +176 -0
  65. data/cookbooks/mysql/templates/default/mysql-server.seed.erb +10 -0
  66. data/cookbooks/mysql/templates/default/port_mysql.erb +3 -0
  67. data/cookbooks/openssl/README.md +37 -0
  68. data/cookbooks/openssl/libraries/secure_password.rb +37 -0
  69. data/cookbooks/openssl/metadata.rb +8 -0
  70. data/cookbooks/openssl/recipes/default.rb +19 -0
  71. data/cookbooks/passenger_enterprise/README.rdoc +8 -0
  72. data/cookbooks/passenger_enterprise/attributes/default.rb +28 -0
  73. data/cookbooks/passenger_enterprise/cc.gemspec +36 -0
  74. data/cookbooks/passenger_enterprise/metadata.json +44 -0
  75. data/cookbooks/passenger_enterprise/metadata.rb +16 -0
  76. data/cookbooks/passenger_enterprise/recipes/apache2.rb +54 -0
  77. data/cookbooks/passenger_enterprise/recipes/default.rb +30 -0
  78. data/cookbooks/passenger_enterprise/recipes/nginx.rb +50 -0
  79. data/cookbooks/passenger_enterprise/templates/default/passenger.conf.erb +2 -0
  80. data/cookbooks/passenger_enterprise/templates/default/passenger.load.erb +1 -0
  81. data/cookbooks/passenger_enterprise/templates/default/passenger_nginx.conf.erb +2 -0
  82. data/cookbooks/ruby_enterprise/README.rdoc +55 -0
  83. data/cookbooks/ruby_enterprise/attributes/default.rb +33 -0
  84. data/cookbooks/ruby_enterprise/cc.gemspec +36 -0
  85. data/cookbooks/ruby_enterprise/definitions/ree_gem.rb +28 -0
  86. data/cookbooks/ruby_enterprise/metadata.json +45 -0
  87. data/cookbooks/ruby_enterprise/metadata.rb +13 -0
  88. data/cookbooks/ruby_enterprise/recipes/default.rb +67 -0
  89. data/data_bags/deploy/authorized_keys.json +9 -0
  90. data/dna.json +25 -0
  91. data/elzar.gemspec +22 -0
  92. data/lib/elzar.rb +21 -0
  93. data/lib/elzar/assistant.rb +77 -0
  94. data/lib/elzar/chef_dna.rb +48 -0
  95. data/lib/elzar/template.rb +24 -0
  96. data/lib/elzar/templates/Gemfile +11 -0
  97. data/lib/elzar/templates/Vagrantfile.erb +16 -0
  98. data/lib/elzar/templates/dna.json +25 -0
  99. data/lib/elzar/templates/solo.rb.erb +6 -0
  100. data/lib/elzar/version.rb +3 -0
  101. data/roles/enterprise_appstack.rb +4 -0
  102. data/roles/plumbing.rb +11 -0
  103. data/roles/postgres_database.rb +4 -0
  104. data/roles/ruby_appstack.rb +4 -0
  105. data/script/install_cookbook +6 -0
  106. data/script/new_cookbook +5 -0
  107. data/site-cookbooks/.gitkeep +0 -0
  108. data/site-cookbooks/curl/README.md +17 -0
  109. data/site-cookbooks/curl/metadata.rb +6 -0
  110. data/site-cookbooks/curl/recipes/default.rb +11 -0
  111. data/site-cookbooks/nginx/CHANGELOG.md +11 -0
  112. data/site-cookbooks/nginx/CONTRIBUTING +29 -0
  113. data/site-cookbooks/nginx/LICENSE +201 -0
  114. data/site-cookbooks/nginx/README.md +76 -0
  115. data/site-cookbooks/nginx/attributes/default.rb +65 -0
  116. data/site-cookbooks/nginx/definitions/nginx_site.rb +35 -0
  117. data/site-cookbooks/nginx/files/default/mime.types +73 -0
  118. data/site-cookbooks/nginx/metadata.rb +89 -0
  119. data/site-cookbooks/nginx/recipes/default.rb +57 -0
  120. data/site-cookbooks/nginx/recipes/source.rb +126 -0
  121. data/site-cookbooks/nginx/templates/default/default-site.erb +11 -0
  122. data/site-cookbooks/nginx/templates/default/nginx.conf.erb +42 -0
  123. data/site-cookbooks/nginx/templates/default/nginx.init.erb +91 -0
  124. data/site-cookbooks/nginx/templates/default/nxdissite.erb +29 -0
  125. data/site-cookbooks/nginx/templates/default/nxensite.erb +38 -0
  126. data/site-cookbooks/passenger/README.md +12 -0
  127. data/site-cookbooks/passenger/attributes/default.rb +3 -0
  128. data/site-cookbooks/passenger/metadata.rb +6 -0
  129. data/site-cookbooks/passenger/recipes/default.rb +39 -0
  130. data/site-cookbooks/passenger/templates/default/passenger_nginx.conf.erb +2 -0
  131. data/site-cookbooks/postgresql/README.md +150 -0
  132. data/site-cookbooks/postgresql/attributes/default.rb +72 -0
  133. data/site-cookbooks/postgresql/metadata.rb +21 -0
  134. data/site-cookbooks/postgresql/recipes/client.rb +40 -0
  135. data/site-cookbooks/postgresql/recipes/default.rb +20 -0
  136. data/site-cookbooks/postgresql/recipes/server.rb +74 -0
  137. data/site-cookbooks/postgresql/recipes/server_debian.rb +62 -0
  138. data/site-cookbooks/postgresql/recipes/server_redhat.rb +82 -0
  139. data/site-cookbooks/postgresql/templates/default/debian.postgresql.conf.erb +499 -0
  140. data/site-cookbooks/postgresql/templates/default/pg_hba.conf.erb +83 -0
  141. data/site-cookbooks/postgresql/templates/default/redhat.postgresql.conf.erb +501 -0
  142. data/site-cookbooks/rails_app/README.md +15 -0
  143. data/site-cookbooks/rails_app/attributes/default.rb +2 -0
  144. data/site-cookbooks/rails_app/files/default/sudoers +26 -0
  145. data/site-cookbooks/rails_app/metadata.rb +6 -0
  146. data/site-cookbooks/rails_app/recipes/default.rb +143 -0
  147. data/site-cookbooks/rails_app/recipes/system_libraries.rb +12 -0
  148. data/site-cookbooks/rails_app/templates/default/pg_hba.conf.erb +84 -0
  149. data/site-cookbooks/rails_app/templates/default/rails_app_nginx.erb +10 -0
  150. data/site-cookbooks/ruby/README.md +12 -0
  151. data/site-cookbooks/ruby/attributes/default.rb +6 -0
  152. data/site-cookbooks/ruby/metadata.rb +6 -0
  153. data/site-cookbooks/ruby/recipes/default.rb +54 -0
  154. data/solo.rb +7 -0
  155. data/upgrade-chef.sh +8 -0
  156. metadata +272 -0
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.join(File.dirname(__FILE__), 'resource_database')
20
+ require File.join(File.dirname(__FILE__), 'provider_database_sql_server')
21
+
22
+ class Chef
23
+ class Resource
24
+ class SqlServerDatabase < Chef::Resource::Database
25
+
26
+ def initialize(name, run_context=nil)
27
+ super
28
+ @resource_name = :sql_server_database
29
+ @provider = Chef::Provider::Database::SqlServer
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require File.join(File.dirname(__FILE__), 'resource_database_user')
20
+ require File.join(File.dirname(__FILE__), 'provider_database_sql_server_user')
21
+
22
+ class Chef
23
+ class Resource
24
+ class SqlServerDatabaseUser < Chef::Resource::DatabaseUser
25
+
26
+ def initialize(name, run_context=nil)
27
+ super
28
+ @resource_name = :sql_server_database_user
29
+ @provider = Chef::Provider::Database::SqlServerUser
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ maintainer "Opscode, Inc."
2
+ maintainer_email "cookbooks@opscode.com"
3
+ license "Apache 2.0"
4
+ description "Sets up the database master or slave"
5
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6
+ version "1.1.0"
7
+
8
+ recipe "database", "Empty placeholder"
9
+ recipe "database::ebs_backup", "Considered deprecated, older way of backing up EBS volumes"
10
+ recipe "database::ebs_volume", "Sets up an EBS volume in EC2 for the database"
11
+ recipe "database::master", "Creates application specific user and database"
12
+ recipe "database::snapshot", "Locks tables and freezes XFS filesystem for replication, assumes EC2 + EBS"
13
+
14
+ depends "mysql", ">= 1.2.0"
15
+ depends "postgresql"
16
+ depends "aws"
17
+ depends "xfs"
18
+
19
+ %w{ debian ubuntu centos suse fedora redhat scientific }.each do |os|
20
+ supports os
21
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Cookbook Name:: database
4
+ # Recipe:: default
5
+ #
6
+ # Copyright 2009, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
@@ -0,0 +1,89 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Cookbook Name:: database
4
+ # Recipe:: ebs_backup
5
+ #
6
+ # Copyright 2009, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ begin
22
+ aws = Chef::DataBagItem.load('aws', 'main')
23
+ Chef::Log.info("Loaded AWS information from DataBagItem aws[#{aws['id']}]")
24
+ rescue
25
+ Chef::Log.fatal("Could not find the 'main' item in the 'aws' data bag")
26
+ raise
27
+ end
28
+
29
+ db_role = String.new
30
+ db_master_role = String.new
31
+ db_type = node[:database][:type]
32
+
33
+ search(:apps) do |app|
34
+ db_role = app["database_#{db_type}_role"] & node.run_list.roles
35
+ db_master_role = app["database_master_role"]
36
+ end
37
+
38
+ ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_master_role}_#{node.chef_environment}")
39
+
40
+ gem_package "dbi"
41
+ gem_package "dbd-mysql"
42
+
43
+ directory "/mnt/aws-config" do
44
+ mode 0700
45
+ owner "root"
46
+ group "root"
47
+ end
48
+
49
+ template "/mnt/aws-config/config" do
50
+ source "aws_config.erb"
51
+ variables(
52
+ :access_key => aws['aws_access_key_id'],
53
+ :secret_key => aws['aws_secret_access_key']
54
+ )
55
+ owner "root"
56
+ group "root"
57
+ mode 0600
58
+ end
59
+
60
+ git "/opt/ec2_mysql" do
61
+ repository "git://github.com/jtimberman/ec2_mysql.git"
62
+ reference "HEAD"
63
+ action :sync
64
+ not_if { ::FileTest.directory?("/opt/ec2_mysql/.git") }
65
+ end
66
+
67
+ %w{backup restore}.each do |file|
68
+ template "/usr/local/bin/db-#{file}.sh" do
69
+ source "ebs-db-#{file}.sh.erb"
70
+ owner "root"
71
+ group "root"
72
+ mode 0700
73
+ variables(
74
+ :mysql_root_passwd => node['mysql']['server_root_password'],
75
+ :mysql_device => node['mysql']['ebs_vol_dev'],
76
+ :ebs_vol_id => ebs_info['volume_id']
77
+ )
78
+ end
79
+ end
80
+
81
+ if db_type == "master" && node.chef_environment == "production"
82
+ template "/etc/cron.d/db-backup" do
83
+ source "ebs-backup-cron.erb"
84
+ owner "root"
85
+ group "root"
86
+ mode 0644
87
+ backup false
88
+ end
89
+ end
@@ -0,0 +1,196 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Author:: AJ Christensen (<aj@opscode.com>)
4
+ # Cookbook Name:: database
5
+ # Recipe:: ebs_volume
6
+ #
7
+ # Copyright 2009-2010, Opscode, Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ if node[:ec2]
23
+ include_recipe "aws"
24
+ include_recipe "xfs"
25
+
26
+ begin
27
+ aws = Chef::DataBagItem.load(:aws, :main)
28
+ Chef::Log.info("Loaded AWS information from DataBagItem aws[#{aws['id']}]")
29
+ rescue
30
+ Chef::Log.fatal("Could not find the 'main' item in the 'aws' data bag")
31
+ raise
32
+ end
33
+
34
+ ebs_vol_dev = node['mysql']['ebs_vol_dev']
35
+ ebs_vol_id = String.new
36
+ db_type = String.new
37
+ db_role = String.new
38
+ master_role = String.new
39
+ slave_role = String.new
40
+ root_pw = String.new
41
+ snapshots_to_keep = String.new
42
+
43
+ search(:apps) do |app|
44
+ if (app["database_master_role"] & node.run_list.roles).length == 1 || (app["database_slave_role"] & node.run_list.roles).length == 1
45
+ master_role = app["database_master_role"]
46
+ slave_role = app["database_slave_role"]
47
+ root_pw = app["mysql_root_password"][node.chef_environment]
48
+ snapshots_to_keep = app["snapshots_to_keep"][node.chef_environment]
49
+
50
+ if (master_role & node.run_list.roles).length == 1
51
+ db_type = "master"
52
+ db_role = master_role
53
+ elsif (slave_role & node.run_list.roles).length == 1
54
+ db_type = "slave"
55
+ db_role = slave_role
56
+ end
57
+
58
+ Chef::Log.info "database::ebs_volume - db_role: #{db_role} db_type: #{db_type}"
59
+ end
60
+ end
61
+
62
+ begin
63
+ ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_role}_#{node.chef_environment}")
64
+ Chef::Log.info("Loaded #{ebs_info['volume_id']} from DataBagItem aws[#{ebs_info['id']}]")
65
+ rescue
66
+ Chef::Log.warn("Could not find the 'ebs_#{db_role}_#{node.chef_environment}' item in the 'aws' data bag")
67
+ ebs_info = Hash.new
68
+ end
69
+
70
+ begin
71
+ master_info = Chef::DataBagItem.load(:aws, "ebs_#{master_role}_#{node.chef_environment}")
72
+ Chef::Log.info "Loaded #{master_info['volume_id']} from DataBagItem aws[#{master_info['id']}]"
73
+ rescue
74
+ Chef::Application.fatal! "Could not load replication masters snapshot details", -41 if db_type == "slave"
75
+ end
76
+
77
+ ruby_block "store_#{db_role}_#{node.chef_environment}_volid" do
78
+ block do
79
+ ebs_vol_id = node[:aws][:ebs_volume]["#{db_role}_#{node.chef_environment}"][:volume_id]
80
+
81
+ unless ebs_info['volume_id']
82
+ item = {
83
+ "id" => "ebs_#{db_role}_#{node.chef_environment}",
84
+ "volume_id" => ebs_vol_id
85
+ }
86
+ Chef::Log.info "Storing volume_id #{item.inspect}"
87
+ databag_item = Chef::DataBagItem.new
88
+ databag_item.data_bag("aws")
89
+ databag_item.raw_data = item
90
+ databag_item.save
91
+ Chef::Log.info("Created #{item['id']} in #{databag_item.data_bag}")
92
+ end
93
+ end
94
+ action :nothing
95
+ end
96
+
97
+ aws_ebs_volume "#{db_role}_#{node.chef_environment}" do
98
+ aws_access_key aws['aws_access_key_id']
99
+ aws_secret_access_key aws['aws_secret_access_key']
100
+ size 50
101
+ device ebs_vol_dev
102
+ snapshots_to_keep snapshots_to_keep
103
+ case db_type
104
+ when "master"
105
+ if ebs_info['volume_id'] && ebs_info['volume_id'] =~ /vol/
106
+ volume_id ebs_info['volume_id']
107
+ action :attach
108
+ elsif ebs_info['volume_id'] && ebs_info['volume_id'] =~ /snap/
109
+ snapshot_id ebs_info['volume_id']
110
+ action [ :create, :attach ]
111
+ else
112
+ action [ :create, :attach ]
113
+ end
114
+ notifies :create, resources(:ruby_block => "store_#{db_role}_#{node.chef_environment}_volid")
115
+ when "slave"
116
+ if master_info['volume_id']
117
+ snapshot_id master_info['volume_id']
118
+ action [:create, :attach]
119
+ else
120
+ Chef::Log.warn("Couldn't detect snapshot ID.")
121
+ action :nothing
122
+ end
123
+ end
124
+ provider "aws_ebs_volume"
125
+ end
126
+
127
+ if db_type == "master"
128
+ Chef::Log.info "Setting up templates for chef-solo snapshots"
129
+ template "/etc/chef/chef-solo-database-snapshot.rb" do
130
+ source "chef-solo-database-snapshot.rb.erb"
131
+ variables :cookbook_path => Chef::Config[:cookbook_path]
132
+ owner "root"
133
+ group "root"
134
+ mode 0600
135
+ end
136
+
137
+ template "/etc/chef/chef-solo-database-snapshot.json" do
138
+ source "chef-solo-database-snapshot.json.erb"
139
+ variables(
140
+ :output => {
141
+ 'db_snapshot' => {
142
+ 'ebs_vol_dev' => node.mysql.ec2_path,
143
+ 'db_role' => db_role,
144
+ 'app_environment' => node.chef_environment,
145
+ 'username' => 'root',
146
+ 'password' => root_pw,
147
+ 'aws_access_key_id' => aws['aws_access_key_id'],
148
+ 'aws_secret_access_key' => aws['aws_secret_access_key'],
149
+ 'snapshots_to_keep' => snapshots_to_keep,
150
+ 'volume_id' => ebs_info['volume_id']
151
+ },
152
+ 'run_list' => [
153
+ "recipe[database::snapshot]"
154
+ ]
155
+ }
156
+ )
157
+ owner "root"
158
+ group "root"
159
+ mode 0600
160
+ end
161
+
162
+ template "/etc/cron.d/chef-solo-database-snapshot" do
163
+ source "chef-solo-database-snapshot.cron.erb"
164
+ variables(
165
+ :json_attribs => "/etc/chef/chef-solo-database-snapshot.json",
166
+ :config_file => "/etc/chef/chef-solo-database-snapshot.rb"
167
+ )
168
+ owner "root"
169
+ group "root"
170
+ mode 0600
171
+ end
172
+ end
173
+
174
+ execute "mkfs.xfs #{ebs_vol_dev}" do
175
+ only_if "xfs_admin -l #{ebs_vol_dev} 2>&1 | grep -qx 'xfs_admin: #{ebs_vol_dev} is not a valid XFS filesystem (unexpected SB magic number 0x00000000)'"
176
+ end
177
+
178
+ %w{ec2_path data_dir}.each do |dir|
179
+ directory node['mysql'][dir] do
180
+ mode 0755
181
+ end
182
+ end
183
+
184
+ mount node['mysql']['ec2_path'] do
185
+ device ebs_vol_dev
186
+ fstype "xfs"
187
+ action :mount
188
+ end
189
+
190
+ mount node['mysql']['data_dir'] do
191
+ device node['mysql']['ec2_path']
192
+ fstype "none"
193
+ options "bind,rw"
194
+ action :mount
195
+ end
196
+ end
@@ -0,0 +1,78 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Cookbook Name:: database
4
+ # Recipe:: master
5
+ #
6
+ # Copyright 2009-2010, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # This is potentially destructive to the nodes mysql password attributes, since
21
+ # we iterate over all the app databags. If this database server provides
22
+ # databases for multiple applications, the last app found in the databags
23
+ # will win out, so make sure the databags have the same passwords set for
24
+ # the root, repl, and debian-sys-maint users.
25
+ #
26
+
27
+ db_info = Hash.new
28
+ root_pw = String.new
29
+
30
+ search(:apps) do |app|
31
+ (app['database_master_role'] & node.run_list.roles).each do |dbm_role|
32
+ %w{ root repl debian }.each do |user|
33
+ user_pw = app["mysql_#{user}_password"]
34
+ if !user_pw.nil? and user_pw[node.chef_environment]
35
+ Chef::Log.debug("Saving password for #{user} as node attribute node['mysql']['server_#{user}_password'")
36
+ node.set['mysql']["server_#{user}_password"] = user_pw[node.chef_environment]
37
+ node.save
38
+ else
39
+ log "A password for MySQL user #{user} was not found in DataBag 'apps' item '#{app["id"]}' for environment ' for #{node.chef_environment}'." do
40
+ level :warn
41
+ end
42
+ log "A random password will be generated by the mysql cookbook and added as 'node.mysql.server_#{user}_password'. Edit the DataBag item to ensure it is set correctly on new nodes" do
43
+ level :warn
44
+ end
45
+ end
46
+ end
47
+ app['databases'].each do |env,db|
48
+ db_info[env] = db
49
+ end
50
+ end
51
+ end
52
+
53
+ include_recipe "mysql::server"
54
+
55
+ connection_info = {:host => "localhost", :username => 'root', :password => node['mysql']['server_root_password']}
56
+
57
+ search(:apps) do |app|
58
+ (app['database_master_role'] & node.run_list.roles).each do |dbm_role|
59
+ app['databases'].each do |env,db|
60
+ if env =~ /#{node.chef_environment}/
61
+ mysql_database "create #{db['database']}" do
62
+ database_name db['database']
63
+ connection connection_info
64
+ action :create
65
+ end
66
+ %W{ % #{node['fqdn']} localhost }.each do |h|
67
+ mysql_database_user db['username'] do
68
+ connection connection_info
69
+ password db['password']
70
+ database_name db['database']
71
+ host h
72
+ action :grant
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end