/cookbooks/mysql/recipes/server.rb

https://bitbucket.org/aarmea/markdown-server · Ruby · 101 lines · 72 code · 11 blank · 18 comment · 2 complexity · dfb8d11bc15822e99f1a5dab3f59412f MD5 · raw file

  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. include_recipe "mysql::client"
  20. case node[:platform]
  21. when "debian","ubuntu"
  22. directory "/var/cache/local/preseeding" do
  23. owner "root"
  24. group "root"
  25. mode 0755
  26. recursive true
  27. end
  28. execute "preseed mysql-server" do
  29. command "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed"
  30. action :nothing
  31. end
  32. template "/var/cache/local/preseeding/mysql-server.seed" do
  33. source "mysql-server.seed.erb"
  34. owner "root"
  35. group "root"
  36. mode "0600"
  37. notifies :run, resources(:execute => "preseed mysql-server"), :immediately
  38. end
  39. template "/etc/mysql/debian.cnf" do
  40. source "debian.cnf.erb"
  41. owner "root"
  42. group "root"
  43. mode "0600"
  44. end
  45. end
  46. package "mysql-server" do
  47. action :install
  48. end
  49. service "mysql" do
  50. service_name value_for_platform([ "centos", "redhat", "suse" ] => {"default" => "mysqld"}, "default" => "mysql")
  51. if (platform?("ubuntu") && node.platform_version.to_f >= 10.04)
  52. restart_command "restart mysql"
  53. stop_command "stop mysql"
  54. start_command "start mysql"
  55. end
  56. supports :status => true, :restart => true, :reload => true
  57. action :nothing
  58. end
  59. template value_for_platform([ "centos", "redhat", "suse" ] => {"default" => "/etc/my.cnf"}, "default" => "/etc/mysql/my.cnf") do
  60. source "my.cnf.erb"
  61. owner "root"
  62. group "root"
  63. mode "0644"
  64. notifies :restart, resources(:service => "mysql"), :immediately
  65. end
  66. begin
  67. t = resources(:template => "/etc/mysql/grants.sql")
  68. rescue
  69. Chef::Log.warn("Could not find previously defined grants.sql resource")
  70. t = template "/etc/mysql/grants.sql" do
  71. source "grants.sql.erb"
  72. owner "root"
  73. group "root"
  74. mode "0600"
  75. action :create
  76. end
  77. end
  78. unless Chef::Config[:solo]
  79. ruby_block "save node data" do
  80. block do
  81. node.save
  82. end
  83. action :create
  84. end
  85. end
  86. execute "mysql-install-privileges" do
  87. command "/usr/bin/mysql -u root -p#{node[:mysql][:server_root_password]} < /etc/mysql/grants.sql"
  88. action :nothing
  89. subscribes :run, resources(:template => "/etc/mysql/grants.sql"), :immediately
  90. end