class MysqlSlaver::StatusFetcher
Attributes
executor[RW]
master_host[RW]
mysql_root_password[RW]
socket_file[RW]
Public Class Methods
new(params)
click to toggle source
# File lib/mysql_slaver/status_fetcher.rb, line 8 def initialize(params) @master_host = params.fetch(:master_host) @socket_file = params.fetch(:socket_file, nil) @mysql_root_password = params.fetch(:mysql_root_password, '') @executor = params.fetch(:executor) { Executor.new(ssh_port: params[:ssh_port]) } end
Public Instance Methods
status()
click to toggle source
# File lib/mysql_slaver/status_fetcher.rb, line 15 def status params = {root_password: mysql_root_password, socket_file: socket_file} cmd = mysql_command("show master status\\G", params) if data = executor.execute(executor.ssh_command(cmd, master_host)) rtn = parse data log "MASTER STATUS - file: #{rtn[:file]}, position: #{rtn[:position]}" rtn else raise Exception.new("Failed to get master status") end end
Private Instance Methods
parse(text)
click to toggle source
# File lib/mysql_slaver/status_fetcher.rb, line 29 def parse(text) file = nil position = nil text.split("\n").each do |line| case line when /File: (mysql-bin\.\d+)/ file = $1 when /Position: (\d+)/ position = $1 end end {file: file, position: position} end