Class: Mysqlknife::Mysql::Kill
- Inherits:
-
Object
- Object
- Mysqlknife::Mysql::Kill
- Defined in:
- lib/mysqlknife/mysql/kill.rb
Instance Attribute Summary collapse
-
#where ⇒ Object
writeonly
Sets the attribute where.
Instance Method Summary collapse
- #check_grants ⇒ Object
- #check_privileges ⇒ Object
- #check_user ⇒ Object
- #clear ⇒ Object
-
#initialize ⇒ Kill
constructor
A new instance of Kill.
- #kill(id) ⇒ Object
- #list ⇒ Object
- #rds? ⇒ Boolean
- #show ⇒ Object
Constructor Details
#initialize ⇒ Kill
Returns a new instance of Kill.
8 9 10 11 |
# File 'lib/mysqlknife/mysql/kill.rb', line 8 def initialize @mysql = MySQL.new @mysql_sql = Mysql::SQL.new end |
Instance Attribute Details
#where=(value) ⇒ Object (writeonly)
Sets the attribute where
6 7 8 |
# File 'lib/mysqlknife/mysql/kill.rb', line 6 def where=(value) @where = value end |
Instance Method Details
#check_grants ⇒ Object
28 29 30 31 32 33 |
# File 'lib/mysqlknife/mysql/kill.rb', line 28 def check_grants sql = @mysql_sql.current_user_grants result = @mysql.execute(sql).first.values.to_s =~ /PROCESS/ return true if result end |
#check_privileges ⇒ Object
35 36 37 |
# File 'lib/mysqlknife/mysql/kill.rb', line 35 def check_privileges check_user || check_grants end |
#check_user ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mysqlknife/mysql/kill.rb', line 21 def check_user sql = @mysql_sql.current_user result = @mysql.execute(sql).first['CURRENT_USER'] =~ /^root\@/ return true if result end |
#clear ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/mysqlknife/mysql/kill.rb', line 13 def clear list.each do |process| kill(process['id']) Mysqlknife::Log.new.kill(process) end end |
#kill(id) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/mysqlknife/mysql/kill.rb', line 62 def kill(id) if check_privileges if rds? @mysql.execute(@mysql_sql.mysql_kill(id)) else @mysql.execute(@mysql_sql.rds_kill(id)) end end end |
#list ⇒ Object
39 40 41 |
# File 'lib/mysqlknife/mysql/kill.rb', line 39 def list @mysql.execute(@mysql_sql.show_processlist(@where)) end |
#rds? ⇒ Boolean
58 59 60 |
# File 'lib/mysqlknife/mysql/kill.rb', line 58 def rds? ! @mysql.execute(@mysql_sql.show_procedure('rds_kill')).first end |
#show ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mysqlknife/mysql/kill.rb', line 43 def show process = list unless process.first.nil? table = Terminal::Table.new do |t| t.add_row(process.first.keys) t.add_separator process.each do |row| t.add_row(row.values) end end puts table end end |