-
-
Save anonymous/b2ce214444b05b235545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mail defined | |
def send_email(subj, message, supportMail="root@localhost") | |
supportMail = ENV['SUPPORT'] unless ENV['SUPPORT'] == nil | |
message = "From: Flexifin Backups <root@#{Socket.gethostname}> | |
To: #{supportMail} | |
Content-type: text/html | |
Subject: #{subj} | |
Date: #{Time.now} | |
#{message}" | |
Net::SMTP.start("smtp-relay.localhost", 25) do |smtp| | |
smtp.send_message message, "root@#{Socket.gethostname}", | |
"#{supportMail}" | |
end | |
end | |
def fsLayout | |
puts "Starting MySQL...\n".green | |
Open3.popen3("/usr/sbin/mysqld --defaults-file=my-tmp.cnf --basedir=/usr --datadir=/tmp/mysql-validation --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/validate-db.err --pid-file=/var/lib/mysql/validate-db.pid") {|stdin, stdout, stderr, wait_thr| | |
begin | |
pid = wait_thr.pid | |
sleep 3 | |
client = Mysql2::Client.new(:default_file => 'my-client.cnf', :default_group => 'client') | |
$results = client.query("SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.TABLES GROUP BY table_schema") | |
puts "Database validation output:\n".yellow.bold.underline | |
$mailInfo = '' | |
$dbOut = '' | |
$results.each do |row| | |
$dbOut += "Database name: #{row['Database']} - Size in (MB): #{row['Size (MB)'].to_f}\n".yellow | |
puts $dbOut | |
$mailInfo = "<tr><td>#{$dbOut}</td></tr>" | |
end | |
puts "\n" | |
send_email( "Validation complete:", $mailInfo ) | |
Process.kill("KILL",wait_thr.pid) | |
exit_status = wait_thr.pid | |
rescue Exception => e | |
puts "Some exception, closing MySQL daemon and aborting!".red.bold | |
puts e.message | |
Process.kill("KILL",wait_thr.pid) | |
exit_status = wait_thr.pid | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment