Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (70 sloc) 2.594 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
include_recipe "joy_of_cooking::daemontools"

src_dir = "/usr/local/src/mysql"
install_dir = "/usr/local/mysql"
mysql_root_password = "password"
mysql_user_name = "app_user"
mysql_user_password = "password"

{
  "cmake" => "2.6.4-5.el5.2",
  "bison" => "2.3-2.1",
  "ncurses-devel" => "5.5-24.20060715"
}.each do |package_name, version_string|
  package package_name do
    action :install
    version version_string
  end
end

user "mysql"

run_unless_marker_file_exists("mysql_5_5_11") do
  execute "download mysql src" do
    command "mkdir -p #{src_dir} && curl -Lsf http://mysql.he.net/Downloads/MySQL-5.5/mysql-5.5.11.tar.gz | tar xvz -C#{src_dir} --strip 1"
  end

  execute "cmake" do
    command "cmake ."
    cwd src_dir
  end

  execute "make" do
    command "make install"
    cwd src_dir
  end
  
  execute "mysql owns #{install_dir}/data" do
    command "chown -R mysql #{install_dir}/data"
  end

  execute "install db" do
    command "#{install_dir}/scripts/mysql_install_db --user=mysql"
    cwd install_dir
  end
end

execute "create daemontools directory" do
  command "mkdir -p /service/mysql"
end

execute "create run script" do
  command "echo -e '#!/bin/sh\nexec /command/setuidgid mysql /usr/local/mysql/bin/mysqld' > /service/mysql/run"
  not_if "ls /service/mysql/run"
end

execute "make run script executable" do
  command "chmod 755 /service/mysql/run"
end

ruby_block "wait for mysql to come up" do
  block do
    Timeout::timeout(60) do
      until system("ls /tmp/mysql.sock")
        sleep 1
      end
    end
  end
end

execute "set the root mysql password" do
  command "#{install_dir}/bin/mysqladmin -uroot password #{mysql_root_password}"
  not_if "#{install_dir}/bin/mysql -uroot -p#{mysql_root_password} -e 'show databases'"
end

execute "create app_user user" do
  command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"CREATE USER '#{mysql_user_name}'@'localhost'\""
  not_if "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SELECT * FROM user where User='#{mysql_user_name}' and Host = 'localhost'\" | grep -q #{mysql_user_name}"
end

execute "set password for app_user" do
  command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"SET PASSWORD FOR '#{mysql_user_name}'@'localhost' = PASSWORD('#{mysql_user_password}')\""
end

execute "grant user all rights (this probably isn't a great idea)" do
  command "#{install_dir}/bin/mysql -u root -p#{mysql_root_password} -D mysql -r -B -N -e \"GRANT ALL on *.* to '#{mysql_user_name}'@'localhost'\""
end
Something went wrong with that request. Please try again.