Class: Synapse::Easy::Haproxy
- Inherits:
-
Object
- Object
- Synapse::Easy::Haproxy
- Includes:
- Fake::Hash
- Defined in:
- lib/synapse/easy/haproxy.rb
Instance Attribute Summary collapse
-
#config_file_path ⇒ Object
Returns the value of attribute config_file_path.
-
#default_balance ⇒ Object
Returns the value of attribute default_balance.
-
#default_log ⇒ Object
Returns the value of attribute default_log.
-
#default_maxconn ⇒ Object
Returns the value of attribute default_maxconn.
-
#default_options ⇒ Object
Returns the value of attribute default_options.
-
#default_retries ⇒ Object
Returns the value of attribute default_retries.
-
#default_timeouts ⇒ Object
Returns the value of attribute default_timeouts.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#do_reloads ⇒ Object
Returns the value of attribute do_reloads.
-
#do_socket ⇒ Object
Returns the value of attribute do_socket.
-
#do_writes ⇒ Object
Returns the value of attribute do_writes.
-
#extra_sections ⇒ Object
Returns the value of attribute extra_sections.
-
#frontends ⇒ Object
Returns the value of attribute frontends.
-
#global ⇒ Object
readonly
Returns the value of attribute global.
-
#global_log_level ⇒ Object
Returns the value of attribute global_log_level.
-
#global_log_server ⇒ Object
Returns the value of attribute global_log_server.
-
#global_maxconn ⇒ Object
Returns the value of attribute global_maxconn.
-
#nbproc ⇒ Object
Returns the value of attribute nbproc.
-
#pid_file_path ⇒ Object
Returns the value of attribute pid_file_path.
-
#reload_command ⇒ Object
Returns the value of attribute reload_command.
-
#socket_file_path ⇒ Object
Returns the value of attribute socket_file_path.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Instance Method Summary collapse
- #config_file_name ⇒ Object
-
#initialize(params = {}) ⇒ Haproxy
constructor
A new instance of Haproxy.
- #instance_id(size = 3) ⇒ Object
- #pid_file_name ⇒ Object
- #socket_file_name ⇒ Object
- #to_synapse ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Haproxy
Returns a new instance of Haproxy.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/synapse/easy/haproxy.rb', line 18 def initialize params={} @do_writes ||= true @do_reloads ||= true @do_socket ||= true @reload_command ||= "haproxy -f '#{config_file_path}' -p '#{pid_file_path}' -st $(cat '#{pid_file_path}' 2>/dev/null|| true)" @global ||= [] @defaults ||= [] @extra_sections ||= {} @nbproc ||= 2 @global_maxconn ||= 4096 @global_log_server = params[:global_log_server] @global_log_server ||= Resolv::Consul.services(:syslog).sample(1).map{|x| "#{x.address}:#{x.port}"}.first @global_log_server ||= "127.0.0.1:514" @global_log_level ||= "local0" @default_log ||= "global" @default_retries ||= 3 @default_maxconn ||= 2048 @default_options ||= [ "option dontlognull", "option redispatch", "option tcpka", ] @default_balance ||= "roundrobin" @default_timeouts ||= { "connect" => 50000, "client" => 72000000, # 2h Timeout "server" => 72000000, # 2h Timeout "queue" => 60000, "check" => 10000, } end |
Instance Attribute Details
#config_file_path ⇒ Object
Returns the value of attribute config_file_path.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def config_file_path @config_file_path end |
#default_balance ⇒ Object
Returns the value of attribute default_balance.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def default_balance @default_balance end |
#default_log ⇒ Object
Returns the value of attribute default_log.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def default_log @default_log end |
#default_maxconn ⇒ Object
Returns the value of attribute default_maxconn.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def default_maxconn @default_maxconn end |
#default_options ⇒ Object
Returns the value of attribute default_options.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def @default_options end |
#default_retries ⇒ Object
Returns the value of attribute default_retries.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def default_retries @default_retries end |
#default_timeouts ⇒ Object
Returns the value of attribute default_timeouts.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def default_timeouts @default_timeouts end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
17 18 19 |
# File 'lib/synapse/easy/haproxy.rb', line 17 def defaults @defaults end |
#do_reloads ⇒ Object
Returns the value of attribute do_reloads.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def do_reloads @do_reloads end |
#do_socket ⇒ Object
Returns the value of attribute do_socket.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def do_socket @do_socket end |
#do_writes ⇒ Object
Returns the value of attribute do_writes.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def do_writes @do_writes end |
#extra_sections ⇒ Object
Returns the value of attribute extra_sections.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def extra_sections @extra_sections end |
#frontends ⇒ Object
Returns the value of attribute frontends.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def frontends @frontends end |
#global ⇒ Object (readonly)
Returns the value of attribute global.
17 18 19 |
# File 'lib/synapse/easy/haproxy.rb', line 17 def global @global end |
#global_log_level ⇒ Object
Returns the value of attribute global_log_level.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def global_log_level @global_log_level end |
#global_log_server ⇒ Object
Returns the value of attribute global_log_server.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def global_log_server @global_log_server end |
#global_maxconn ⇒ Object
Returns the value of attribute global_maxconn.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def global_maxconn @global_maxconn end |
#nbproc ⇒ Object
Returns the value of attribute nbproc.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def nbproc @nbproc end |
#pid_file_path ⇒ Object
Returns the value of attribute pid_file_path.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def pid_file_path @pid_file_path end |
#reload_command ⇒ Object
Returns the value of attribute reload_command.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def reload_command @reload_command end |
#socket_file_path ⇒ Object
Returns the value of attribute socket_file_path.
11 12 13 |
# File 'lib/synapse/easy/haproxy.rb', line 11 def socket_file_path @socket_file_path end |
#workdir ⇒ Object
Returns the value of attribute workdir.
17 18 19 |
# File 'lib/synapse/easy/haproxy.rb', line 17 def workdir @workdir end |
Instance Method Details
#config_file_name ⇒ Object
63 64 65 |
# File 'lib/synapse/easy/haproxy.rb', line 63 def config_file_name "#{instance_id}.cfg" end |
#instance_id(size = 3) ⇒ Object
53 54 55 |
# File 'lib/synapse/easy/haproxy.rb', line 53 def instance_id size=3 @instance_id ||= SecureRandom.hex(size) end |
#pid_file_name ⇒ Object
69 70 71 |
# File 'lib/synapse/easy/haproxy.rb', line 69 def pid_file_name "#{instance_id}.pid" end |
#socket_file_name ⇒ Object
66 67 68 |
# File 'lib/synapse/easy/haproxy.rb', line 66 def socket_file_name "#{instance_id}.sock" end |
#to_synapse ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/synapse/easy/haproxy.rb', line 98 def to_synapse FileUtils.mkdir_p workdir.to_s unless Dir.exists? workdir.to_s { reload_command: reload_command, do_writes: do_writes, do_reloads: do_reloads, do_socket: do_socket, config_file_path: config_file_path, socket_file_path: socket_file_path, global: global, defaults: defaults, extra_sections: extra_sections }.with_indifferent_access end |