Module: HAProxyCTL
- Includes:
- Environment
- Defined in:
- lib/haproxyctl.rb,
lib/haproxyctl/version.rb,
lib/haproxyctl/environment.rb
Defined Under Namespace
Modules: Environment
Constant Summary
collapse
- VERSION =
'1.2.0'
Instance Attribute Summary
Attributes included from Environment
#config, #config_path, #exec
Instance Method Summary
collapse
#check_running, #has_exec?, #pidfile, #socket, #version
Instance Method Details
#display_usage! ⇒ Object
82
83
84
85
|
# File 'lib/haproxyctl.rb', line 82
def display_usage!
puts usage
exit
end
|
#reload(pid) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/haproxyctl.rb', line 31
def reload(pid)
if pid
puts "gracefully stopping connections on pid #{pid}..."
system("#{exec} -f #{config_path} -sf #{pid}")
puts "checking if connections still alive on #{pid}..."
nowpid = check_running
while pid == nowpid
puts "still haven't killed old pid.
waiting 2s for existing connections to die...
(ctrl+c to stop this check)"
sleep 2
nowpid = check_running || 0
end
puts "reloaded haproxy on pid #{nowpid}"
else
puts 'haproxy is not running!'
end
end
|
#start ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/haproxyctl.rb', line 8
def start
puts 'starting haproxy...'
system("#{exec} -f #{config_path} -D -p #{pidfile}")
newpid = check_running
if newpid =~ /^\d+$/
puts "haproxy is running on pid #{newpid}"
return true
else
puts 'error. haproxy did not start!'
return nil
end
end
|
#stop(pid) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/haproxyctl.rb', line 21
def stop(pid)
if pid
puts "stopping haproxy on pid #{pid}..."
system("kill #{pid}") || system("kill -9 #{pid}")
puts '... stopped'
else
puts 'haproxy is not running!'
end
end
|
#unixsock(command) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/haproxyctl.rb', line 50
def unixsock(command)
output = []
runs = 0
begin
ctl = UNIXSocket.open(socket)
if ctl
ctl.write "#{command}\r\n"
else
puts "cannot talk to #{socket}"
end
rescue Errno::EPIPE
ctl.close
sleep 0.5
runs += 1
if runs < 4
retry
else
puts "the unix socket at #{socket} closed before we could complete this request"
exit
end
end
while (line = ctl.gets)
unless line =~ /Unknown command/
output << line
end
end
ctl.close
output
end
|
#usage ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/haproxyctl.rb', line 87
def usage
"usage: \#{$PROGRAM_NAME} <argument>\nwhere <argument> can be:\n start : start haproxy unless it is already running\n stop : stop an existing haproxy\n restart : immediately shutdown and restart\n reload : gracefully terminate existing connections, reload \#{config_path}\n status : is haproxy running? on what ports per lsof?\n configcheck : check \#{config_path}\n nagios : nagios-friendly status for running process and listener\n cloudkick : cloudkick.com-friendly status and metric for connected users\n show health : show status of all frontends and backend servers\n show backends : show status of backend pools of servers\n enable all <server> : re-enable a server previously in maint mode on multiple backends\n disable all <server> : disable a server from every backend it exists\n enable all EXCEPT <server> : like 'enable all', but re-enables every backend except for <server>\n disable all EXCEPT <server> : like 'disable all', but disables every backend except for <server>\n clear counters : clear max statistics counters (add 'all' for all counters)\n help : this message\n prompt : toggle interactive mode with prompt\n quit : disconnect\n show info : report information about the running process\n show stat : report counters for each proxy and server\n show errors : report last request and response errors for each proxy\n show sess [id] : report the list of current sessions or dump this session\n get weight : report a server's current weight\n set weight : change a server's weight\n set timeout : change a timeout setting\n disable server : set a server in maintenance mode\n enable server : re-enable a server that was previously in maintenance mode\n version : version of this script\n"
end
|