Module: HAProxyCTL::Environment
- Included in:
- HAProxyCTL
- Defined in:
- lib/haproxyctl/environment.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#exec ⇒ Object
Returns the value of attribute exec.
-
#pidof ⇒ Object
Sets the attribute pidof.
Instance Method Summary collapse
-
#check_running ⇒ String?
(also: #pidof)
Returns the PID of HAProxy as a string, if running.
- #has_exec? ⇒ Boolean
- #pidfile ⇒ Object
- #socket ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/haproxyctl/environment.rb', line 3 def config @config end |
#config_path ⇒ Object
Returns the value of attribute config_path.
3 4 5 |
# File 'lib/haproxyctl/environment.rb', line 3 def config_path @config_path end |
#exec ⇒ Object
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
3 4 5 |
# File 'lib/haproxyctl/environment.rb', line 3 def pidof=(value) @pidof = value end |
Instance Method Details
#check_running ⇒ String? Also known as: pidof
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
17 18 19 |
# File 'lib/haproxyctl/environment.rb', line 17 def has_exec? !exec.nil? end |
#pidfile ⇒ Object
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 |
#socket ⇒ Object
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 |
#version ⇒ Object
5 6 7 |
# File 'lib/haproxyctl/environment.rb', line 5 def version puts "HAProxyCTL #{HAProxyCTL::VERSION}" end |