Module: Synapse::Rails::Haproxy
- Included in:
- Synapse::Rails
- Defined in:
- lib/synapse/rails/haproxy.rb
Instance Attribute Summary collapse
- #config_file_path ⇒ Object
- #defaults ⇒ Object
- #do_reloads ⇒ Object
- #do_socket ⇒ Object
- #do_writes ⇒ Object
- #extra_sections ⇒ Object
- #global ⇒ Object
- #pid_file_path ⇒ Object
- #reload_command ⇒ Object
- #socket_file_path ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#config_file_path ⇒ Object
17 18 19 20 21 |
# 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 ⇒ Object
44 45 46 |
# 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 ⇒ Object
35 36 37 |
# File 'lib/synapse/rails/haproxy.rb', line 35 def do_reloads @do_reloads || true end |
#do_socket ⇒ Object
38 39 40 |
# File 'lib/synapse/rails/haproxy.rb', line 38 def do_socket @do_socket || true end |
#do_writes ⇒ Object
32 33 34 |
# File 'lib/synapse/rails/haproxy.rb', line 32 def do_writes @do_writes || true end |
#extra_sections ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
41 42 43 |
# File 'lib/synapse/rails/haproxy.rb', line 41 def global @global || ["daemon","maxconn 4096","stats socket #{socket_file_path} mode 666 level admin"] end |
#pid_file_path ⇒ Object
27 28 29 30 31 |
# 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 ⇒ Object
7 8 9 |
# 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 ⇒ Object
22 23 24 25 26 |
# 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 |
Instance Method Details
#haproxy ⇒ Object
60 61 62 63 64 |
# 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 ⇒ Object
57 58 59 |
# File 'lib/synapse/rails/haproxy.rb', line 57 def instance @instance ||= SecureRandom.hex(3) end |
#instance_name ⇒ Object
10 11 12 |
# File 'lib/synapse/rails/haproxy.rb', line 10 def instance_name "synapse_#{instance}" end |
#workdir ⇒ Object
13 14 15 16 |
# 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 |