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