class DanarchyDeploy::Services::MySQL::NewServer

Public Class Methods

new(os, mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 6
def self.new(os, mysql, options)
  self.generate_root_mycnf(mysql, options)

  if os == 'gentoo'
    self.gentoo_new_mysql(mysql, options)
  elsif os == 'opensuse'
    self.opensuse_new_mysql(mysql, options)
  elsif %w[debian ubuntu].include?(os)
    self.debian_new_mysql(mysql, options)
  elsif %w[centos redhat].include?(os)
    self.centos_new_mysql(mysql, options)
  end
end

Private Class Methods

centos_new_mysql(mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 42
def self.centos_new_mysql(mysql, options)
  puts "   ! CentOS/Redhat MySQL configuration not yet implemented!"
  
end
debian_new_mysql(mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 38
def self.debian_new_mysql(mysql, options)
  puts "   ! Debian/Ubuntu MySQL configuration not yet implemented!"
end
generate_root_mycnf(mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 51
def self.generate_root_mycnf(mysql, options)
  return if File.exist?(mysql[:default_file])
  puts "   |+ Generating #{mysql[:default_file]} file."
  password = SecureRandom.base64(14)
  source = options[:deploy_dir] +
           '/templates/services/mysql/root_my.cnf.erb'

  templates = [{ target: mysql[:default_file],
                 source: source,
                 variables: {
                   host: 'localhost',
                   user: 'root',
                   pass: password,
                   port: '3306' }
               }]

  DanarchyDeploy::Templater.new(templates, options)
end
gentoo_new_mysql(mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 22
def self.gentoo_new_mysql(mysql, options)
  puts "\n > Performing first time MySQL configuration."
  cmd = 'emerge --config mariadb'
  config_result = DanarchyDeploy::Helpers.run_command(cmd, options)

  if config_result[:stderr]
    abort('   |! ERROR: Failed to configure MySQL')
  else config_result[:stdout]
    puts "   |+ MySQL configured successfully"
    puts config_result[:stdout]
  end

  puts "\n > Starting MySQL."
  DanarchyDeploy::Services::Init.init_manager('gentoo', 'mysql', 'start', options)
end
opensuse_new_mysql(mysql, options) click to toggle source
# File lib/danarchy_deploy/services/mysql/new_server.rb, line 47
def self.opensuse_new_mysql(mysql, options)
  puts "   ! OpenSUSE MySQL configuration not yet implemented!"
end