module Synapse::Rails::Haproxy

Attributes

config_file_path[W]
defaults[W]
do_reloads[W]
do_socket[W]
do_writes[W]
extra_sections[W]
global[W]
pid_file_path[W]
reload_command[W]
socket_file_path[W]

Public Instance Methods

config_file_path() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 17
def config_file_path
  @config_file_path ||= workdir.join("tmp","#{instance_name}.cfg").to_s
  FileUtils.mkdir_p File.dirname @config_file_path
  @config_file_path
end
defaults() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 44
def defaults
  @defaults || ["log global","option dontlognull","maxconn 1024","retries 3","timeout connect 5s","timeout client 60s","timeout server 60s","option redispatch","balance roundrobin"]
end
do_reloads() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 35
def do_reloads
  @do_reloads || true
end
do_socket() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 38
def do_socket
  @do_socket || true
end
do_writes() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 32
def do_writes
  @do_writes || true
end
extra_sections() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 47
def extra_sections
  @extra_sections || {
    "listen stats 127.0.0.1:#{Freeport.port}" => [
      "mode http",
      "stats enable",
      "stats uri /",
      "stats refresh 5s"
    ]
  }
end
global() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 41
def global
  @global || ["daemon","maxconn 4096","stats socket #{socket_file_path} mode 666 level admin"]
end
haproxy() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 60
def haproxy
  %i{reload_command config_file_path socket_file_path do_writes do_reloads do_socket global defaults extra_sections}.collect do |section|
    [section,self.send(section)]
  end.to_h.with_indifferent_access
end
instance() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 57
def instance
  @instance ||= SecureRandom.hex(3)
end
instance_name() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 10
def instance_name
  "synapse_#{instance}"
end
pid_file_path() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 27
def pid_file_path
  @pid_file_path ||= workdir.join("tmp","pids","#{instance_name}.pid").to_s
  FileUtils.mkdir_p File.dirname @pid_file_path
  @pid_file_path
end
reload_command() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 7
def reload_command
  @reload_command || "haproxy -f '#{config_file_path}' -p '#{pid_file_path}' -st $(cat '#{pid_file_path}' 2>/dev/null|| true)"
end
socket_file_path() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 22
def socket_file_path 
  @socket_file_path ||= workdir.join("tmp","sockets","#{instance_name}.sock").to_s
  FileUtils.mkdir_p File.dirname @socket_file_path
  @socket_file_path
end
workdir() click to toggle source
# File lib/synapse/rails/haproxy.rb, line 13
def workdir
  @workdir ||= ::Rails.root unless ::Rails.root.to_s.size > 42
  @workdir ||= Pathname.new "/tmp"       
end