class SimpleAdapter

Public Instance Methods

call(env) click to toggle source
# File bin/galera-ha, line 43
def call(env)
  $0 = "/usr/local/bin/galera-ha"
  mysql_connect
  body = [""]
  if @synced == 'Synced'
   [
    200,
    { 'Content-Type' => 'text/plain' },
    body
  ]
  else
   [
   504,
    { 'Content-Type' => 'text/plain' },
    body
  ]
  end 
end
mysql_connect() click to toggle source
# File bin/galera-ha, line 17
def mysql_connect

  Timeout::timeout($config["server"]["query_timeout"]) do
  begin
        mysql = Mysql2::Client.new(
        :host => $config["client"]["host"],
        :port => $config["client"]["port"],
        :username => $config["client"]["user"],
        :password => $config["client"]["pass"]
      )
    wsrep_state = mysql.query("SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment'")
    mysql.close
  rescue => e
    puts e.message
  end 
  if ! wsrep_state.nil?
    @synced = wsrep_state.first['Value']
  else
    @synced = 'none'
  end
end
rescue Timeout::Error
  @synced = 'none'
end