Class: VGH::System::MySQL
- Inherits:
-
Object
- Object
- VGH::System::MySQL
- Defined in:
- lib/vgh/system/mysql.rb
Overview
This class checks if a local MySQL server is present and running. The credentials need to be specified in the app’s configuration file.
Usage
mysql = MySQL.new
mysql.flush
# run backup
mysql.unlock
Instance Method Summary collapse
-
#commands_present? ⇒ Boolean
Check if server is running and we have the right credentials.
-
#flush ⇒ Object
Lock & Flush the MySQL tables.
-
#initialize ⇒ MySQL
constructor
Load defaults.
-
#mysql_exists? ⇒ Boolean
Check if server is running and we have the right credentials.
-
#mysql_password ⇒ String
Get MySQL password.
-
#mysql_user ⇒ String
Get MySQL user.
-
#unlock ⇒ Object
Unlock the MySQL tables.
Constructor Details
#initialize ⇒ MySQL
Load defaults
18 19 20 21 |
# File 'lib/vgh/system/mysql.rb', line 18 def initialize @mysqladmin_cmd = '/usr/bin/mysqladmin' @mysql_cmd = '/usr/bin/mysql' end |
Instance Method Details
#commands_present? ⇒ Boolean
Check if server is running and we have the right credentials
37 38 39 40 41 42 43 |
# File 'lib/vgh/system/mysql.rb', line 37 def commands_present? commands_present = false if File.exists?(@mysqladmin_cmd) and File.exists?(@mysql_cmd) commands_present = true end return commands_present end |
#flush ⇒ Object
Lock & Flush the MySQL tables
61 62 63 64 65 66 |
# File 'lib/vgh/system/mysql.rb', line 61 def flush if mysql_exists? .info 'Locking MySQL tables...' `#{@mysql} -u#{mysql_user} -p#{mysql_password} -e "FLUSH TABLES WITH READ LOCK"` end end |
#mysql_exists? ⇒ Boolean
Check if server is running and we have the right credentials
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vgh/system/mysql.rb', line 47 def mysql_exists? mysql_exists = false server_present = system "#{@mysqladmin_cmd} -s ping" if commands_present? if server_present and mysql_user.nil? and mysql_password.nil? .warn 'WARNING: MySQL exists but no credentials were found!' elsif ! server_present and ! mysql_user.nil? and ! mysql_password.nil? .warn 'WARNING: MySQL credentials exist but no local server was found!' elsif server_present and ! mysql_user.nil? and ! mysql_password.nil? mysql_exists = true end return mysql_exists end |
#mysql_password ⇒ String
Get MySQL password
31 32 33 |
# File 'lib/vgh/system/mysql.rb', line 31 def mysql_password @mysql_password ||= config[:mysql_password] end |
#mysql_user ⇒ String
Get MySQL user
25 26 27 |
# File 'lib/vgh/system/mysql.rb', line 25 def mysql_user @mysql_user ||= config[:mysql_user] end |
#unlock ⇒ Object
Unlock the MySQL tables
69 70 71 72 73 74 |
# File 'lib/vgh/system/mysql.rb', line 69 def unlock if mysql_exists? .info 'Unlocking MySQL tables...' `#{@mysql} -u#{mysql_user} -p#{mysql_password} -e "UNLOCK TABLES"` end end |