Public instance methods
Create the database from the current database_environment
# File lib/moonshine/manifest/rails/mysql.rb, line 54 54: def mysql_database 55: exec "mysql_database", 56: :command => mysql_query("create database #{database_environment[:database]};"), 57: :unless => mysql_query("show create database #{database_environment[:database]};"), 58: :require => service('mysql'), 59: :notify => exec('rails_bootstrap') 60: end
Noop /etc/mysql/debian-start, which does some nasty table scans on MySQL start.
# File lib/moonshine/manifest/rails/mysql.rb, line 64 64: def mysql_fixup_debian_start 65: file '/etc/mysql/debian-start', 66: :ensure => :present, 67: :content => "#!/bin/bash\nexit 0", 68: :mode => '755', 69: :owner => 'root', 70: :require => package('mysql-server') 71: end
Install the mysql rubygem and dependencies
# File lib/moonshine/manifest/rails/mysql.rb, line 30 30: def mysql_gem 31: gem('mysql') 32: end
Installs mysql-server from apt and enables the mysql service. Also creates a configuration file at /etc/mysql/conf.d/moonshine.cnf. See templates/moonshine.cnf for configuration options.
# File lib/moonshine/manifest/rails/mysql.rb, line 7 7: def mysql_server 8: package 'mysql-server', :ensure => :installed 9: service 'mysql', :ensure => :running, :require => [ 10: package('mysql-server'), 11: package('mysql') 12: ] 13: #ensure the mysql key is present on the configuration hash 14: configure(:mysql => {}) 15: file '/etc/mysql', :ensure => :directory 16: file '/etc/mysql/conf.d', :ensure => :directory 17: file '/etc/mysql/conf.d/innodb.cnf', 18: :ensure => :present, 19: :content => template(File.join(File.dirname(__FILE__), 'templates', 'innodb.cnf.erb')), 20: :before => package('mysql-server') 21: file '/etc/mysql/conf.d/moonshine.cnf', 22: :ensure => :present, 23: :content => template(File.join(File.dirname(__FILE__), 'templates', 'moonshine.cnf.erb')), 24: :require => package('mysql-server'), 25: :notify => service('mysql') 26: file '/etc/logrotate.d/varlogmysql.conf', :ensure => :absent 27: end
GRANT the database user specified in the current database_environment permisson to access the database with the supplied password
# File lib/moonshine/manifest/rails/mysql.rb, line 36 36: def mysql_user 37: grant ="GRANT ALL PRIVILEGES \nON \#{database_environment[:database]}.*\nTO \#{database_environment[:username]}@localhost\nIDENTIFIED BY '\#{database_environment[:password]}';\nFLUSH PRIVILEGES;\n" 38: 39: exec "mysql_user", 40: :command => mysql_query(grant), 41: :unless => "mysqlshow -u#{database_environment[:username]} -p#{database_environment[:password]} #{database_environment[:database]}", 42: :require => exec('mysql_database'), 43: :before => exec('rake tasks') 44: end