forked from benhoskings/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.rb
62 lines (56 loc) · 1.62 KB
/
mysql.rb
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
dep 'mysql.gem' do
requires 'mysql.managed'
provides []
end
dep 'mysql access' do
requires 'existing mysql db'
define_var :db_user, :default => :username
define_var :db_host, :default => 'localhost'
met? { mysql "use #{var(:db_name)}", var(:db_user) }
meet { mysql %Q{GRANT ALL PRIVILEGES ON #{var :db_name}.* TO '#{var :db_user}'@'#{var :db_host}' IDENTIFIED BY '#{var :db_password}'} }
end
dep 'existing mysql db' do
requires 'mysql configured'
met? { mysql("SHOW DATABASES").split("\n")[1..-1].any? {|l| /\b#{var :db_name}\b/ =~ l } }
meet { mysql "CREATE DATABASE #{var :db_name}" }
end
dep 'mysql configured' do
requires 'mysql root password'
requires 'mysql started'
end
dep 'mysql root password' do
requires 'mysql.managed'
met? { raw_shell("mysql -u root -e \"SHOW DATABASES;\"").stderr.empty? }
meet {
sudo("service mysql stop")
raw_shell("killall mysqld", :sudo => true)
Thread.new {
sudo("mysqld_safe --skip-grant-tables")
}
sleep 3
shell("mysql -e \"UPDATE mysql.user SET Password=PASSWORD('') WHERE User='root';FLUSH PRIVILEGES;\"")
}
after {
sudo("killall mysqld")
sleep 3
sudo("service mysql start")
}
end
dep 'mysql started' do
met? {
!sudo("service mysql status").scan(/start\/running/).empty?
}
meet {
sudo("service mysql start")
}
end
dep 'mysql.managed' do
installs {
via :apt, %w[mysql-server libmysqlclient-dev]
via :macports, 'mysql5-server'
}
provides 'mysql'
after :on => :osx do
sudo "ln -s #{Babushka::MacportsHelper.prefix / 'lib/mysql5/bin/mysql*'} #{Babushka::MacportsHelper.prefix / 'bin/'}"
end
end