Module: Rhapr::Environment
- Included in:
- Interface
- Defined in:
- lib/rhapr/environment.rb
Instance Attribute Summary collapse
-
#config ⇒ String
readonly
The raw contents of the HAProxy configuration file.
-
#config_path ⇒ String?
readonly
The path to the HAProxy configuration file, or nil if not found.
-
#exec ⇒ String?
readonly
The path to the HAProxy executable will be returned, if found.
-
#haproxy_pid ⇒ Object
readonly
Returns the value of attribute haproxy_pid.
-
#socket_path ⇒ String
readonly
@todo: Should there be an ENV var for this? Perhaps allow config-less runs of rhapr?.
Instance Method Summary collapse
-
#check_running ⇒ String?
(also: #pidof)
@todo: Look for something other than pidof, for searching the process list.
-
#has_exec? ⇒ true, false
Whether or not the HAProxy executable can be found.
-
#pid ⇒ String
@todo: Should there even be an assumption? Does HAProxy create a pid file, if not told to by the configuration? @todo: Should there be an ENV var for this? Perhaps allow config-less runs of rhapr?.
-
#socket ⇒ UNIXSocket
A connection to the HAProxy Socket.
Instance Attribute Details
#config ⇒ String (readonly)
Returns The raw contents of the HAProxy configuration file.
25 26 27 |
# File 'lib/rhapr/environment.rb', line 25 def config @config end |
#config_path ⇒ String? (readonly)
Returns The path to the HAProxy configuration file, or nil if not found. Set the ENV variable $HAPROXY_CONFIG to override defaults.
8 9 10 |
# File 'lib/rhapr/environment.rb', line 8 def config_path @config_path end |
#exec ⇒ String? (readonly)
Returns The path to the HAProxy executable will be returned, if found. Set ENV variable $HAPROXY_BIN to override.
40 41 42 |
# File 'lib/rhapr/environment.rb', line 40 def exec @exec end |
#haproxy_pid ⇒ Object (readonly)
Returns the value of attribute haproxy_pid.
5 6 7 |
# File 'lib/rhapr/environment.rb', line 5 def haproxy_pid @haproxy_pid end |
#socket_path ⇒ String (readonly)
@todo: Should there be an ENV var for this? Perhaps allow config-less runs of rhapr?
71 72 73 |
# File 'lib/rhapr/environment.rb', line 71 def socket_path @socket_path end |
Instance Method Details
#check_running ⇒ String? Also known as: pidof
@todo: Look for something other than pidof, for searching the process list.
Could read from the pid file, but there's potential that it will go stale.
91 92 93 94 95 96 |
# File 'lib/rhapr/environment.rb', line 91 def check_running pidof = `pidof haproxy` pidof.strip! return pidof unless pidof.empty? end |
#has_exec? ⇒ true, false
Returns Whether or not the HAProxy executable can be found.
35 36 37 |
# File 'lib/rhapr/environment.rb', line 35 def has_exec? !exec.nil? end |
#pid ⇒ String
@todo: Should there even be an assumption? Does HAProxy create a pid file, if not told to by the configuration? @todo: Should there be an ENV var for this? Perhaps allow config-less runs of rhapr?
81 82 83 84 85 86 |
# File 'lib/rhapr/environment.rb', line 81 def pid @pid ||= begin config.match /pidfile ([^\s]*)/ $1 || '/var/run/haproxy.pid' end end |
#socket ⇒ UNIXSocket
Returns A connection to the HAProxy Socket.
60 61 62 63 64 65 66 |
# File 'lib/rhapr/environment.rb', line 60 def socket begin UNIXSocket.open(socket_path) rescue Errno::EACCES => e raise RuntimeError.new("Could not open a socket with HAProxy. Error message: #{e.}") end end |