server_maint 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. data/.gitmodules +21 -0
  2. data/lib/cookbooks/aws/CHANGELOG.md +11 -0
  3. data/lib/cookbooks/aws/CONTRIBUTING +29 -0
  4. data/lib/cookbooks/aws/LICENSE +201 -0
  5. data/lib/cookbooks/aws/README.md +271 -0
  6. data/lib/cookbooks/aws/attributes/default.rb +20 -0
  7. data/lib/cookbooks/aws/libraries/ec2.rb +58 -0
  8. data/lib/cookbooks/aws/metadata.rb +7 -0
  9. data/lib/cookbooks/aws/providers/ebs_volume.rb +236 -0
  10. data/lib/cookbooks/aws/providers/elastic_ip.rb +90 -0
  11. data/lib/cookbooks/aws/providers/elastic_lb.rb +24 -0
  12. data/lib/cookbooks/aws/providers/resource_tag.rb +93 -0
  13. data/lib/cookbooks/aws/recipes/default.rb +25 -0
  14. data/lib/cookbooks/aws/resources/ebs_volume.rb +17 -0
  15. data/lib/cookbooks/aws/resources/elastic_ip.rb +11 -0
  16. data/lib/cookbooks/aws/resources/elastic_lb.rb +10 -0
  17. data/lib/cookbooks/aws/resources/resource_tag.rb +11 -0
  18. data/lib/cookbooks/database/.gitignore +1 -0
  19. data/lib/cookbooks/database/CHANGELOG.md +51 -0
  20. data/lib/cookbooks/database/CONTRIBUTING +29 -0
  21. data/lib/cookbooks/database/LICENSE +201 -0
  22. data/lib/cookbooks/database/README.md +468 -0
  23. data/lib/cookbooks/database/libraries/provider_database_mysql.rb +103 -0
  24. data/lib/cookbooks/database/libraries/provider_database_mysql_user.rb +76 -0
  25. data/lib/cookbooks/database/libraries/provider_database_postgresql.rb +131 -0
  26. data/lib/cookbooks/database/libraries/provider_database_postgresql_user.rb +83 -0
  27. data/lib/cookbooks/database/libraries/provider_database_sql_server.rb +109 -0
  28. data/lib/cookbooks/database/libraries/provider_database_sql_server_user.rb +106 -0
  29. data/lib/cookbooks/database/libraries/resource_database.rb +119 -0
  30. data/lib/cookbooks/database/libraries/resource_database_user.rb +90 -0
  31. data/lib/cookbooks/database/libraries/resource_mysql_database.rb +34 -0
  32. data/lib/cookbooks/database/libraries/resource_mysql_database_user.rb +34 -0
  33. data/lib/cookbooks/database/libraries/resource_postgresql_database.rb +35 -0
  34. data/lib/cookbooks/database/libraries/resource_postgresql_database_user.rb +35 -0
  35. data/lib/cookbooks/database/libraries/resource_sql_server_database.rb +34 -0
  36. data/lib/cookbooks/database/libraries/resource_sql_server_database_user.rb +34 -0
  37. data/lib/cookbooks/database/metadata.rb +22 -0
  38. data/lib/cookbooks/database/recipes/default.rb +20 -0
  39. data/lib/cookbooks/database/recipes/ebs_backup.rb +89 -0
  40. data/lib/cookbooks/database/recipes/ebs_volume.rb +204 -0
  41. data/lib/cookbooks/database/recipes/master.rb +78 -0
  42. data/lib/cookbooks/database/recipes/mysql.rb +20 -0
  43. data/lib/cookbooks/database/recipes/postgresql.rb +20 -0
  44. data/lib/cookbooks/database/recipes/snapshot.rb +62 -0
  45. data/lib/cookbooks/database/templates/default/app_grants.sql.erb +8 -0
  46. data/lib/cookbooks/database/templates/default/aws_config.erb +3 -0
  47. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.cron.erb +6 -0
  48. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.json.erb +1 -0
  49. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.rb.erb +6 -0
  50. data/lib/cookbooks/database/templates/default/ebs-backup-cron.erb +2 -0
  51. data/lib/cookbooks/database/templates/default/ebs-db-backup.sh.erb +8 -0
  52. data/lib/cookbooks/database/templates/default/ebs-db-restore.sh.erb +10 -0
  53. data/lib/cookbooks/database/templates/default/s3cfg.erb +27 -0
  54. data/lib/cookbooks/mysql/.gitignore +5 -0
  55. data/lib/cookbooks/mysql/CHANGELOG.md +86 -0
  56. data/lib/cookbooks/mysql/CONTRIBUTING +29 -0
  57. data/lib/cookbooks/mysql/Gemfile +8 -0
  58. data/lib/cookbooks/mysql/LICENSE +201 -0
  59. data/lib/cookbooks/mysql/README.md +227 -0
  60. data/lib/cookbooks/mysql/attributes/client.rb +50 -0
  61. data/lib/cookbooks/mysql/attributes/server.rb +153 -0
  62. data/lib/cookbooks/mysql/files/default/tests/minitest/server_test.rb +36 -0
  63. data/lib/cookbooks/mysql/files/default/tests/minitest/support/helpers.rb +11 -0
  64. data/lib/cookbooks/mysql/libraries/helpers.rb +33 -0
  65. data/lib/cookbooks/mysql/metadata.rb +140 -0
  66. data/lib/cookbooks/mysql/recipes/client.rb +59 -0
  67. data/lib/cookbooks/mysql/recipes/default.rb +20 -0
  68. data/lib/cookbooks/mysql/recipes/ruby.rb +36 -0
  69. data/lib/cookbooks/mysql/recipes/server.rb +216 -0
  70. data/lib/cookbooks/mysql/recipes/server_ec2.rb +51 -0
  71. data/lib/cookbooks/mysql/templates/default/debian.cnf.erb +12 -0
  72. data/lib/cookbooks/mysql/templates/default/grants.sql.erb +15 -0
  73. data/lib/cookbooks/mysql/templates/default/my.cnf.erb +211 -0
  74. data/lib/cookbooks/mysql/templates/default/mysql-server.seed.erb +10 -0
  75. data/lib/cookbooks/mysql/templates/default/port_mysql.erb +3 -0
  76. data/lib/cookbooks/mysql/templates/windows/my.cnf.erb +61 -0
  77. data/lib/cookbooks/mysql/test/features/query_database.feature +26 -0
  78. data/lib/cookbooks/mysql/test/features/step_definitions/mysql_steps.rb +47 -0
  79. data/lib/cookbooks/mysql/test/features/support/env.rb +3 -0
  80. data/lib/cookbooks/mysql/test/features/support/mysql_helpers.rb +51 -0
  81. data/lib/cookbooks/mysql/test/kitchen/Kitchenfile +5 -0
  82. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/.gitignore +1 -0
  83. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/README.md +63 -0
  84. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/attributes/default.rb +27 -0
  85. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/metadata.rb +10 -0
  86. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/recipes/client.rb +20 -0
  87. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/recipes/server.rb +72 -0
  88. data/lib/cookbooks/openssl/CHANGELOG.md +0 -0
  89. data/lib/cookbooks/openssl/CONTRIBUTING +29 -0
  90. data/lib/cookbooks/openssl/LICENSE +201 -0
  91. data/lib/cookbooks/openssl/README.md +37 -0
  92. data/lib/cookbooks/openssl/libraries/secure_password.rb +37 -0
  93. data/lib/cookbooks/openssl/metadata.rb +8 -0
  94. data/lib/cookbooks/openssl/recipes/default.rb +19 -0
  95. data/lib/cookbooks/postgresql/CHANGELOG.md +35 -0
  96. data/lib/cookbooks/postgresql/CONTRIBUTING +29 -0
  97. data/lib/cookbooks/postgresql/LICENSE +201 -0
  98. data/lib/cookbooks/postgresql/README.md +148 -0
  99. data/lib/cookbooks/postgresql/attributes/default.rb +103 -0
  100. data/lib/cookbooks/postgresql/metadata.rb +21 -0
  101. data/lib/cookbooks/postgresql/recipes/client.rb +26 -0
  102. data/lib/cookbooks/postgresql/recipes/default.rb +20 -0
  103. data/lib/cookbooks/postgresql/recipes/ruby.rb +40 -0
  104. data/lib/cookbooks/postgresql/recipes/server.rb +64 -0
  105. data/lib/cookbooks/postgresql/recipes/server_debian.rb +64 -0
  106. data/lib/cookbooks/postgresql/recipes/server_redhat.rb +77 -0
  107. data/lib/cookbooks/postgresql/templates/default/debian.postgresql.conf.erb +499 -0
  108. data/lib/cookbooks/postgresql/templates/default/pg_hba.conf.erb +83 -0
  109. data/lib/cookbooks/postgresql/templates/default/redhat.postgresql.conf.erb +501 -0
  110. data/lib/cookbooks/sqlite/.gitignore +4 -0
  111. data/lib/cookbooks/sqlite/CHANGELOG.md +3 -0
  112. data/lib/cookbooks/sqlite/CONTRIBUTING +29 -0
  113. data/lib/cookbooks/sqlite/Gemfile +2 -0
  114. data/lib/cookbooks/sqlite/LICENSE +201 -0
  115. data/lib/cookbooks/sqlite/README.md +36 -0
  116. data/lib/cookbooks/sqlite/metadata.rb +12 -0
  117. data/lib/cookbooks/sqlite/recipes/default.rb +30 -0
  118. data/lib/cookbooks/sqlite/test/kitchen/Kitchenfile +1 -0
  119. data/lib/cookbooks/xfs/CHANGELOG.md +0 -0
  120. data/lib/cookbooks/xfs/CONTRIBUTING +29 -0
  121. data/lib/cookbooks/xfs/LICENSE +201 -0
  122. data/lib/cookbooks/xfs/README.md +30 -0
  123. data/lib/cookbooks/xfs/metadata.rb +12 -0
  124. data/lib/cookbooks/xfs/recipes/default.rb +26 -0
  125. data/lib/server_maint/version.rb +1 -1
  126. metadata +127 -4
@@ -0,0 +1,11 @@
1
+ module Helpers
2
+ module Mysql
3
+ include MiniTest::Chef::Assertions
4
+ include MiniTest::Chef::Context
5
+ include MiniTest::Chef::Resources
6
+
7
+ def assert_secure_password(type)
8
+ node["mysql"]["server_#{type}_password"].length.must_be_close_to(20, 8)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
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
+ module Opscode
20
+ module Mysql
21
+ module Helpers
22
+
23
+ def debian_before_squeeze?
24
+ platform?("debian") && (node.platform_version.to_f < 6.0)
25
+ end
26
+
27
+ def ubuntu_before_lucid?
28
+ platform?("ubuntu") && (node.platform_version.to_f < 10.0)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,140 @@
1
+ name "mysql"
2
+ maintainer "Opscode, Inc."
3
+ maintainer_email "cookbooks@opscode.com"
4
+ license "Apache 2.0"
5
+ description "Installs and configures mysql for client or server"
6
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7
+ version "1.3.0"
8
+ recipe "mysql", "Includes the client recipe to configure a client"
9
+ recipe "mysql::client", "Installs packages required for mysql clients using run_action magic"
10
+ recipe "mysql::server", "Installs packages required for mysql servers w/o manual intervention"
11
+ recipe "mysql::server_ec2", "Performs EC2-specific mountpoint manipulation"
12
+
13
+ %w{ debian ubuntu centos suse fedora redhat scientific amazon freebsd windows mac_os_x }.each do |os|
14
+ supports os
15
+ end
16
+
17
+ depends "openssl"
18
+ depends "build-essential"
19
+ suggests "homebrew"
20
+ suggests "windows"
21
+
22
+ attribute "mysql/server_root_password",
23
+ :display_name => "MySQL Server Root Password",
24
+ :description => "Randomly generated password for the mysqld root user",
25
+ :default => "randomly generated"
26
+
27
+ attribute "mysql/bind_address",
28
+ :display_name => "MySQL Bind Address",
29
+ :description => "Address that mysqld should listen on",
30
+ :default => "ipaddress"
31
+
32
+ attribute "mysql/data_dir",
33
+ :display_name => "MySQL Data Directory",
34
+ :description => "Location of mysql databases",
35
+ :default => "/var/lib/mysql"
36
+
37
+ attribute "mysql/conf_dir",
38
+ :display_name => "MySQL Conf Directory",
39
+ :description => "Location of mysql conf files",
40
+ :default => "/etc/mysql"
41
+
42
+ attribute "mysql/ec2_path",
43
+ :display_name => "MySQL EC2 Path",
44
+ :description => "Location of mysql directory on EC2 instance EBS volumes",
45
+ :default => "/mnt/mysql"
46
+
47
+ attribute "mysql/reload_action",
48
+ :display_name => "MySQL conf file reload action",
49
+ :description => "Action to take when mysql conf files are modified",
50
+ :default => "reload"
51
+
52
+ attribute "mysql/tunable",
53
+ :display_name => "MySQL Tunables",
54
+ :description => "Hash of MySQL tunable attributes",
55
+ :type => "hash"
56
+
57
+ attribute "mysql/tunable/key_buffer",
58
+ :display_name => "MySQL Tuntable Key Buffer",
59
+ :default => "250M"
60
+
61
+ attribute "mysql/tunable/max_connections",
62
+ :display_name => "MySQL Tunable Max Connections",
63
+ :default => "800"
64
+
65
+ attribute "mysql/tunable/wait_timeout",
66
+ :display_name => "MySQL Tunable Wait Timeout",
67
+ :default => "180"
68
+
69
+ attribute "mysql/tunable/net_read_timeout",
70
+ :display_name => "MySQL Tunable Net Read Timeout",
71
+ :default => "30"
72
+
73
+ attribute "mysql/tunable/net_write_timeout",
74
+ :display_name => "MySQL Tunable Net Write Timeout",
75
+ :default => "30"
76
+
77
+ attribute "mysql/tunable/back_log",
78
+ :display_name => "MySQL Tunable Back Log",
79
+ :default => "128"
80
+
81
+ attribute "mysql/tunable/table_cache",
82
+ :display_name => "MySQL Tunable Table Cache for MySQL < 5.1.3",
83
+ :default => "128"
84
+
85
+ attribute "mysql/tunable/table_open_cache",
86
+ :display_name => "MySQL Tunable Table Cache for MySQL >= 5.1.3",
87
+ :default => "128"
88
+
89
+ attribute "mysql/tunable/max_heap_table_size",
90
+ :display_name => "MySQL Tunable Max Heap Table Size",
91
+ :default => "32M"
92
+
93
+ attribute "mysql/tunable/expire_logs_days",
94
+ :display_name => "MySQL Exipre Log Days",
95
+ :default => "10"
96
+
97
+ attribute "mysql/tunable/max_binlog_size",
98
+ :display_name => "MySQL Max Binlog Size",
99
+ :default => "100M"
100
+
101
+ attribute "mysql/client",
102
+ :display_name => "MySQL Connector/C Client",
103
+ :description => "Hash of MySQL client attributes",
104
+ :type => "hash"
105
+
106
+ attribute "mysql/client/version",
107
+ :display_name => "MySQL Connector/C Version",
108
+ :default => "6.0.2"
109
+
110
+ attribute "mysql/client/arch",
111
+ :display_name => "MySQL Connector/C Architecture",
112
+ :default => "win32"
113
+
114
+ attribute "mysql/client/package_file",
115
+ :display_name => "MySQL Connector/C Package File Name",
116
+ :default => "mysql-connector-c-6.0.2-win32.msi"
117
+
118
+ attribute "mysql/client/url",
119
+ :display_name => "MySQL Connector/C Download URL",
120
+ :default => "http://www.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.0.2-win32.msi/from/http://mysql.mirrors.pair.com/"
121
+
122
+ attribute "mysql/client/package_name",
123
+ :display_name => "MySQL Connector/C Registry DisplayName",
124
+ :default => "MySQL Connector C 6.0.2"
125
+
126
+ attribute "mysql/client/basedir",
127
+ :display_name => "MySQL Connector/C Base Install Directory",
128
+ :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2"
129
+
130
+ attribute "mysql/client/lib_dir",
131
+ :display_name => "MySQL Connector/C Library Directory (containing libmysql.dll)",
132
+ :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\lib\\opt"
133
+
134
+ attribute "mysql/client/bin_dir",
135
+ :display_name => "MySQL Connector/C Executable Directory",
136
+ :default => "C:\\Program Files (x86)\\MySQL\\Connector C 6.0.2\\bin"
137
+
138
+ attribute "mysql/client/ruby_dir",
139
+ :display_name => "Ruby Executable Directory which should gain MySQL support",
140
+ :default => "system ruby"
@@ -0,0 +1,59 @@
1
+ #
2
+ # Cookbook Name:: mysql
3
+ # Recipe:: client
4
+ #
5
+ # Copyright 2008-2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ # Include Opscode helper in Recipe class to get access
21
+ # to debian_before_squeeze? and ubuntu_before_lucid?
22
+ ::Chef::Recipe.send(:include, Opscode::Mysql::Helpers)
23
+
24
+ case node['platform']
25
+ when "windows"
26
+ package_file = node['mysql']['client']['package_file']
27
+ remote_file "#{Chef::Config[:file_cache_path]}/#{package_file}" do
28
+ source node['mysql']['client']['url']
29
+ not_if { File.exists? "#{Chef::Config[:file_cache_path]}/#{package_file}" }
30
+ end
31
+
32
+ windows_package node['mysql']['client']['packages'].first do
33
+ source "#{Chef::Config[:file_cache_path]}/#{package_file}"
34
+ end
35
+ windows_path node['mysql']['client']['bin_dir'] do
36
+ action :add
37
+ end
38
+ def package(*args, &blk)
39
+ windows_package(*args, &blk)
40
+ end
41
+ when "mac_os_x"
42
+ include_recipe 'homebrew'
43
+ end
44
+
45
+ node['mysql']['client']['packages'].each do |mysql_pack|
46
+ package mysql_pack do
47
+ action :install
48
+ end
49
+ end
50
+
51
+ if platform? 'windows'
52
+ ruby_block "copy libmysql.dll into ruby path" do
53
+ block do
54
+ require 'fileutils'
55
+ FileUtils.cp "#{node['mysql']['client']['lib_dir']}\\libmysql.dll", node['mysql']['client']['ruby_dir']
56
+ end
57
+ not_if { File.exist?("#{node['mysql']['client']['ruby_dir']}\\libmysql.dll") }
58
+ end
59
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Cookbook Name:: mysql
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2008-2009, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ include_recipe "mysql::client"
@@ -0,0 +1,36 @@
1
+ #
2
+ # Cookbook Name:: mysql
3
+ # Recipe:: ruby
4
+ #
5
+ # Author:: Jesse Howarth (<him@jessehowarth.com>)
6
+ # Author:: Jamie Winsor (<jamie@vialstudios.com>)
7
+ #
8
+ # Copyright 2008-2012, Opscode, Inc.
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+
23
+ execute "apt-get update" do
24
+ ignore_failure true
25
+ action :nothing
26
+ end.run_action(:run) if node['platform_family'] == "debian"
27
+
28
+ node.set['build_essential']['compiletime'] = true
29
+ include_recipe "build-essential"
30
+ include_recipe "mysql::client"
31
+
32
+ node['mysql']['client']['packages'].each do |mysql_pack|
33
+ resources("package[#{mysql_pack}]").run_action(:install)
34
+ end
35
+
36
+ chef_gem "mysql"
@@ -0,0 +1,216 @@
1
+ #
2
+ # Cookbook Name:: mysql
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2008-2011, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ ::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)
21
+
22
+ include_recipe "mysql::client"
23
+
24
+ if Chef::Config[:solo]
25
+ missing_attrs = %w{
26
+ server_debian_password server_root_password server_repl_password
27
+ }.select do |attr|
28
+ node["mysql"][attr].nil?
29
+ end.map { |attr| "node['mysql']['#{attr}']" }
30
+
31
+ if !missing_attrs.empty?
32
+ Chef::Application.fatal!([
33
+ "You must set #{missing_attrs.join(', ')} in chef-solo mode.",
34
+ "For more information, see https://github.com/opscode-cookbooks/mysql#chef-solo-note"
35
+ ].join(' '))
36
+ end
37
+ else
38
+ # generate all passwords
39
+ node.set_unless['mysql']['server_debian_password'] = secure_password
40
+ node.set_unless['mysql']['server_root_password'] = secure_password
41
+ node.set_unless['mysql']['server_repl_password'] = secure_password
42
+ end
43
+
44
+ if platform?(%w{debian ubuntu})
45
+
46
+ directory "/var/cache/local/preseeding" do
47
+ owner "root"
48
+ group node['mysql']['root_group']
49
+ mode 0755
50
+ recursive true
51
+ end
52
+
53
+ execute "preseed mysql-server" do
54
+ command "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed"
55
+ action :nothing
56
+ end
57
+
58
+ template "/var/cache/local/preseeding/mysql-server.seed" do
59
+ source "mysql-server.seed.erb"
60
+ owner "root"
61
+ group node['mysql']['root_group']
62
+ mode "0600"
63
+ notifies :run, resources(:execute => "preseed mysql-server"), :immediately
64
+ end
65
+
66
+ template "#{node['mysql']['conf_dir']}/debian.cnf" do
67
+ source "debian.cnf.erb"
68
+ owner "root"
69
+ group node['mysql']['root_group']
70
+ mode "0600"
71
+ end
72
+
73
+ end
74
+
75
+ if platform? 'windows'
76
+ package_file = node['mysql']['package_file']
77
+
78
+ remote_file "#{Chef::Config[:file_cache_path]}/#{package_file}" do
79
+ source node['mysql']['url']
80
+ not_if { File.exists? "#{Chef::Config[:file_cache_path]}/#{package_file}" }
81
+ end
82
+
83
+ windows_package node['mysql']['server']['packages'].first do
84
+ source "#{Chef::Config[:file_cache_path]}/#{package_file}"
85
+ end
86
+
87
+ def package(*args, &blk)
88
+ windows_package(*args, &blk)
89
+ end
90
+ end
91
+
92
+ node['mysql']['server']['packages'].each do |package_name|
93
+ package package_name do
94
+ action :install
95
+ end
96
+ end
97
+
98
+ unless platform?(%w{mac_os_x})
99
+
100
+ directory node['mysql']['confd_dir'] do
101
+ owner "mysql" unless platform? 'windows'
102
+ group "mysql" unless platform? 'windows'
103
+ action :create
104
+ recursive true
105
+ end
106
+
107
+ if platform? 'windows'
108
+ require 'win32/service'
109
+
110
+ windows_path node['mysql']['bin_dir'] do
111
+ action :add
112
+ end
113
+
114
+ windows_batch "install mysql service" do
115
+ command "\"#{node['mysql']['bin_dir']}\\mysqld.exe\" --install #{node['mysql']['service_name']}"
116
+ not_if { Win32::Service.exists?(node['mysql']['service_name']) }
117
+ end
118
+ end
119
+
120
+ service "mysql" do
121
+ service_name node['mysql']['service_name']
122
+ if node['mysql']['use_upstart']
123
+ restart_command "restart mysql"
124
+ stop_command "stop mysql"
125
+ start_command "start mysql"
126
+ end
127
+ supports :status => true, :restart => true, :reload => true
128
+ action :enable
129
+ end
130
+
131
+ skip_federated = case node['platform']
132
+ when 'fedora', 'ubuntu', 'amazon'
133
+ true
134
+ when 'centos', 'redhat', 'scientific'
135
+ node['platform_version'].to_f < 6.0
136
+ else
137
+ false
138
+ end
139
+
140
+ template "#{node['mysql']['conf_dir']}/my.cnf" do
141
+ source "my.cnf.erb"
142
+ owner "root" unless platform? 'windows'
143
+ group node['mysql']['root_group'] unless platform? 'windows'
144
+ mode "0644"
145
+ case node['mysql']['reload_action']
146
+ when 'restart'
147
+ notifies :restart, resources(:service => "mysql"), :immediately
148
+ when 'reload'
149
+ notifies :reload, resources(:service => "mysql"), :immediately
150
+ else
151
+ Chef::Log.info "my.cnf updated but mysql.reload_action is #{node['mysql']['reload_action']}. No action taken."
152
+ end
153
+ variables :skip_federated => skip_federated
154
+ end
155
+ end
156
+
157
+ unless Chef::Config[:solo]
158
+ ruby_block "save node data" do
159
+ block do
160
+ node.save
161
+ end
162
+ action :create
163
+ end
164
+ end
165
+
166
+ # set the root password for situations that don't support pre-seeding.
167
+ # (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
168
+ execute "assign-root-password" do
169
+ command "\"#{node['mysql']['mysqladmin_bin']}\" -u root password \"#{node['mysql']['server_root_password']}\""
170
+ action :run
171
+ only_if "\"#{node['mysql']['mysql_bin']}\" -u root -e 'show databases;'"
172
+ end
173
+
174
+ # Homebrew has its own way to do databases
175
+ if platform?(%w{mac_os_x})
176
+
177
+ execute "mysql-install-db" do
178
+ command "mysql_install_db --verbose --user=`whoami` --basedir=\"$(brew --prefix mysql)\" --datadir=#{node['mysql']['data_dir']} --tmpdir=/tmp"
179
+ environment('TMPDIR' => nil)
180
+ action :run
181
+ creates "#{node['mysql']['data_dir']}/mysql"
182
+ end
183
+
184
+ else
185
+ grants_path = node['mysql']['grants_path']
186
+ begin
187
+ t = resources("template[#{grants_path}]")
188
+ rescue
189
+ Chef::Log.info("Could not find previously defined grants.sql resource")
190
+ t = template grants_path do
191
+ source "grants.sql.erb"
192
+ owner "root" unless platform? 'windows'
193
+ group node['mysql']['root_group'] unless platform? 'windows'
194
+ mode "0600"
195
+ action :create
196
+ end
197
+ end
198
+
199
+ if platform? 'windows'
200
+ windows_batch "mysql-install-privileges" do
201
+ command "\"#{node['mysql']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
202
+ action :nothing
203
+ subscribes :run, resources("template[#{grants_path}]"), :immediately
204
+ end
205
+ else
206
+ execute "mysql-install-privileges" do
207
+ command "\"#{node['mysql']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
208
+ action :nothing
209
+ subscribes :run, resources("template[#{grants_path}]"), :immediately
210
+ end
211
+ end
212
+
213
+ service "mysql" do
214
+ action :start
215
+ end
216
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Cookbook Name:: mysql
3
+ # Recipe:: default
4
+ #
5
+ # Copyright 2008-2009, Opscode, Inc.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+
21
+ if (node.attribute?('ec2') && ! FileTest.directory?(node['mysql']['ec2_path']))
22
+
23
+ service "mysql" do
24
+ action :stop
25
+ end
26
+
27
+ execute "install-mysql" do
28
+ command "mv #{node['mysql']['data_dir']} #{node['mysql']['ec2_path']}"
29
+ not_if do FileTest.directory?(node['mysql']['ec2_path']) end
30
+ end
31
+
32
+ [node['mysql']['ec2_path'], node['mysql']['data_dir']].each do |dir|
33
+ directory dir do
34
+ owner "mysql"
35
+ group "mysql"
36
+ end
37
+ end
38
+
39
+ mount node['mysql']['data_dir'] do
40
+ device node['mysql']['ec2_path']
41
+ fstype "none"
42
+ options "bind,rw"
43
+ action [:mount, :enable]
44
+ end
45
+
46
+ service "mysql" do
47
+ action :start
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,12 @@
1
+ [client]
2
+ host = localhost
3
+ user = debian-sys-maint
4
+ password = <%= node['mysql']['server_debian_password'] %>
5
+ socket = <%= node['mysql']['socket'] %>
6
+
7
+ [mysql_upgrade]
8
+ host = localhost
9
+ user = debian-sys-maint
10
+ password = <%= node['mysql']['server_debian_password'] %>
11
+ socket = <%= node['mysql']['socket'] %>
12
+ basedir = /usr
@@ -0,0 +1,15 @@
1
+ # Generated by Chef for <%= node['hostname'] %>.
2
+ # Local modifications will be overwritten.
3
+
4
+ <% case node['platform'] -%>
5
+ <% when "debian","ubuntu" -%>
6
+ GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<%= node[:mysql][:server_debian_password] %>' WITH GRANT OPTION;
7
+ <% end -%>
8
+ # Grant replication for a slave user.
9
+ GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '<%= node['mysql']['server_repl_password'] %>';
10
+
11
+ # Set the server root password. This should be preseeded by the package installation.
12
+ <% if node['mysql']['allow_remote_root'] -%>
13
+ GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node['mysql']['server_root_password'] %>' WITH GRANT OPTION;
14
+ <% end -%>
15
+ SET PASSWORD FOR 'root'@'localhost' = PASSWORD('<%= node['mysql']['server_root_password'] %>');