Class: ProxyMgr::Haproxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxymgr/haproxy.rb,
lib/proxymgr/haproxy/state.rb,
lib/proxymgr/haproxy/server.rb,
lib/proxymgr/haproxy/socket.rb,
lib/proxymgr/haproxy/control.rb,
lib/proxymgr/haproxy/process.rb,
lib/proxymgr/haproxy/updater.rb,
lib/proxymgr/haproxy/socket_manager.rb

Defined Under Namespace

Classes: Control, Process, Server, Socket, SocketManager, State, Updater

Instance Method Summary collapse

Constructor Details

#initialize(path, config_file, opts = {}) ⇒ Haproxy

Returns a new instance of Haproxy.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/proxymgr/haproxy.rb', line 11

def initialize(path, config_file, opts = {})
  @path             = path
  @config_file      = config_file

  @socket_path      = opts[:socket]
  @global_config    = opts[:global]
  @defaults_config  = opts[:defaults]

  @socket           = @socket_path ? Socket.new(@socket_path) : nil

  @control          = nil
end

Instance Method Details

#shutdownObject



41
42
43
44
# File 'lib/proxymgr/haproxy.rb', line 41

def shutdown
  @state.stop
  @socket_manager.shutdown
end

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/proxymgr/haproxy.rb', line 28

def start
  @socket         = @socket_path ? Socket.new(@socket_path) : nil
  @control        = Control.new(@path, @config_file)
  opts            = {:defaults    => @defaults_config,
                     :global      => @global_config,
                     :socket_path => @socket_path}
  @socket_manager = SocketManager.new
  @state          = State.new(@control, @config_file, @socket_manager, @socket, opts)
  @updater        = Updater.new(@socket)

  @state.start
end

#update_backends(watchers) ⇒ Object



46
47
48
49
# File 'lib/proxymgr/haproxy.rb', line 46

def update_backends(watchers)
  changeset = @updater.produce_changeset(watchers)
  @state.update_state(watchers, changeset)
end

#versionObject



24
25
26
# File 'lib/proxymgr/haproxy.rb', line 24

def version
  `#{@path} -v`[/version ([\d\.]+)/, 1].to_f
end