Module: HAProxyCTL::Environment

Included in:
HAProxyCTL
Defined in:
lib/haproxyctl/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/haproxyctl/environment.rb', line 3

def config
  @config
end

#config_pathObject

Returns the value of attribute config_path.



3
4
5
# File 'lib/haproxyctl/environment.rb', line 3

def config_path
  @config_path
end

#execObject

Returns the value of attribute exec.



3
4
5
# File 'lib/haproxyctl/environment.rb', line 3

def exec
  @exec
end

#pidof=(value) ⇒ Object

Sets the attribute pidof

Parameters:

  • value

    the value to set the attribute pidof to.



3
4
5
# File 'lib/haproxyctl/environment.rb', line 3

def pidof=(value)
  @pidof = value
end

Instance Method Details

#check_runningString? Also known as: pidof

Returns the PID of HAProxy as a string, if running. Nil otherwise.

Returns:

  • (String, nil)

    Returns the PID of HAProxy as a string, if running. Nil otherwise.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/haproxyctl/environment.rb', line 60

def check_running
  if File.exists?(pidfile)
    pid = File.read(pidfile)
    pid.strip!
  end

  # verify this pid exists and is haproxy
  if pid =~ /^\d+$/ and `ps -p #{pid} -o cmd=` =~ /#{exec}/
    return pid
  end
end

#has_exec?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/haproxyctl/environment.rb', line 17

def has_exec?
  !exec.nil?
end

#pidfileObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/haproxyctl/environment.rb', line 46

def pidfile
  if config.match(/pidfile \s*([^\s]*)/)
    @pidfile = Regexp.last_match[1]
  else
    std_pid = '/var/run/haproxy.pid'
    if File.exists?(std_pid)
      @pidfile = std_pid
    else
      fail("Expecting 'pidfile <pid_file_path>' in #{config_path} or a pid file in #{std_pid}")
    end
  end
end

#socketObject



39
40
41
42
43
44
# File 'lib/haproxyctl/environment.rb', line 39

def socket
  @socket ||= begin
    config.match /stats\s+socket \s*([^\s]*)/
    Regexp.last_match[1] || fail("Expecting 'stats socket <UNIX_socket_path>' in #{config_path}")
  end
end

#versionObject



5
6
7
# File 'lib/haproxyctl/environment.rb', line 5

def version
  puts "HAProxyCTL #{HAProxyCTL::VERSION}"
end