haproxyctl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +314 -0
- data/Rakefile +2 -0
- data/bin/haproxyctl +164 -0
- data/haproxyctl +164 -0
- data/haproxyctl.gemspec +18 -0
- data/install-haproxy/haproxy_src_install.sh +82 -0
- data/lib/haproxyctl.rb +122 -0
- data/lib/haproxyctl/environment.rb +71 -0
- data/lib/haproxyctl/version.rb +3 -0
- data/rhapr/.gitignore +4 -0
- data/rhapr/.rspec +1 -0
- data/rhapr/Gemfile +4 -0
- data/rhapr/Rakefile +14 -0
- data/rhapr/lib/rhapr.rb +6 -0
- data/rhapr/lib/rhapr/environment.rb +99 -0
- data/rhapr/lib/rhapr/interface.rb +111 -0
- data/rhapr/lib/rhapr/version.rb +3 -0
- data/rhapr/rhapr.gemspec +22 -0
- data/rhapr/spec/config_fixtures/basic_haproxy.cfg +34 -0
- data/rhapr/spec/config_fixtures/crappy_haproxy.cfg +4 -0
- data/rhapr/spec/config_fixtures/pid_test_haproxy.cfg +6 -0
- data/rhapr/spec/quality_spec.rb +11 -0
- data/rhapr/spec/rhapr/environment_spec.rb +132 -0
- data/rhapr/spec/rhapr/interface_spec.rb +82 -0
- data/rhapr/spec/spec_helper.rb +11 -0
- data/rhapr/spec/support/config_fixtures.rb +53 -0
- data/rhapr/spec/support/custom_matchers.rb +44 -0
- metadata +97 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (C) 2010-2012
|
2
|
+
author: Carlo Flores <github@petalphile.com>
|
3
|
+
contributors: Scott Gonyea, John A. Barbuto, Ben Lovett,
|
4
|
+
Till Klampaeckel, Erik Osterman
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,314 @@
|
|
1
|
+
HAProxyCTL
|
2
|
+
==========
|
3
|
+
|
4
|
+
This is a simple wrapper to make life with HAProxy a little more convenient.
|
5
|
+
|
6
|
+
* Acts as an init script for start, stop, reload, restart, etc
|
7
|
+
* Leverages 'socket' to enable and disable servers on the fly
|
8
|
+
* Formats server weight and backends in a readable way
|
9
|
+
* Provides Nagios and Cloudkick health checks
|
10
|
+
* chkconfig/service-able for Redhat folk
|
11
|
+
|
12
|
+
[Here](http://scale10x.biggiantnerds.com) is a presentation about it.
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
On most UNIX, assuming HAProxy is in the $PATH:
|
18
|
+
|
19
|
+
git clone git@github.com:flores/haproxyctl.git
|
20
|
+
ln -s haproxyctl/haproxyctl /etc/init.d/haproxyctl
|
21
|
+
|
22
|
+
For chkconfig/RedHat/Centos, add:
|
23
|
+
|
24
|
+
chkconfig --add haproxyctl
|
25
|
+
|
26
|
+
There is also an HAProxy source installation script. This installs not only the steps above but latest HAProxy sources!
|
27
|
+
|
28
|
+
Options
|
29
|
+
-----------------
|
30
|
+
<pre>
|
31
|
+
# ./haproxyctl help
|
32
|
+
usage: ./haproxyctl <argument>
|
33
|
+
where argument can be:
|
34
|
+
start: start haproxy unless it is already running
|
35
|
+
stop: stop an existing haproxy
|
36
|
+
restart: immediately shutdown and restart
|
37
|
+
reload: gracefully terminate existing connections, reload /etc/haproxy/haproxy.cfg
|
38
|
+
status: is haproxy running? on what ports per lsof?
|
39
|
+
configcheck: check /etc/haproxy/haproxy.cfg
|
40
|
+
nagios: nagios-friendly status for running process and listener
|
41
|
+
cloudkick: cloudkick.com-friendly status and metric for connected users
|
42
|
+
show health: show status of all frontends and backend servers
|
43
|
+
show backends: show status of backend pools of servers
|
44
|
+
enable all <server>: re-enable a server previously in maint mode on multiple backends
|
45
|
+
disable all <server>: disable a server from every backend it exists
|
46
|
+
enable all EXCEPT <server>: like 'enable all', but re-enables every backend except for <server>
|
47
|
+
disable all EXCEPT <server>: like 'disable all', but disables every backend except for <server>
|
48
|
+
clear counters: clear max statistics counters (add 'all' for all counters)
|
49
|
+
help: this message
|
50
|
+
prompt: toggle interactive mode with prompt
|
51
|
+
quit: disconnect
|
52
|
+
show info: report information about the running process
|
53
|
+
show stat: report counters for each proxy and server
|
54
|
+
show errors: report last request and response errors for each proxy
|
55
|
+
show sess [id]: report the list of current sessions or dump this session
|
56
|
+
get weight: report a server's current weight
|
57
|
+
set weight: change a server's weight
|
58
|
+
set timeout: change a timeout setting
|
59
|
+
disable server: set a server in maintenance mode
|
60
|
+
enable server: re-enable a server that was previously in maintenance mode
|
61
|
+
</pre>
|
62
|
+
|
63
|
+
Examples
|
64
|
+
--------
|
65
|
+
|
66
|
+
## Status check
|
67
|
+
<pre>
|
68
|
+
./haproxyctl status
|
69
|
+
haproxy is running on pid 23162.
|
70
|
+
these ports are used and guys are connected:
|
71
|
+
173.255.194.115:www->98.154.245.132:52025 (ESTABLISHED)
|
72
|
+
173.255.194.115:www->97.89.32.126:52043 (ESTABLISHED)
|
73
|
+
*:www (LISTEN)
|
74
|
+
*:53093
|
75
|
+
173.255.194.115:www->83.39.69.106:19338 (ESTABLISHED)
|
76
|
+
</pre>
|
77
|
+
|
78
|
+
## Errors to the backend servers
|
79
|
+
<pre>
|
80
|
+
./haproxyctl "show errors"
|
81
|
+
[04/Feb/2011:21:05:59.542] frontend http (#1): invalid request
|
82
|
+
src 209.59.188.205, session #39574, backend <NONE> (#-1), server <NONE> (#-1)
|
83
|
+
request length 125 bytes, error at position 27:
|
84
|
+
|
85
|
+
00000 GET /logs/images/stuff/someurl
|
86
|
+
00070+ HTTP/1.1\r\n
|
87
|
+
00081 Host: wet.biggiantnerds.com\r\n
|
88
|
+
00110 Accept: */*\r\n
|
89
|
+
00123 \r\n
|
90
|
+
</pre>
|
91
|
+
## Human readable health check
|
92
|
+
<pre>
|
93
|
+
./haproxyctl "show health"
|
94
|
+
pxname svname status weight
|
95
|
+
http FRONTEND OPEN
|
96
|
+
sinatra sinatra_downoi DOWN 1
|
97
|
+
sinatra sinatra_rindica DOWN 1
|
98
|
+
sinatra sinatra_guinea UP 1
|
99
|
+
sinatra BACKEND UP 1
|
100
|
+
ei guinea UP 1
|
101
|
+
ei belem UP 1
|
102
|
+
ei BACKEND UP 1
|
103
|
+
drop guinea UP 1
|
104
|
+
drop belem UP 1
|
105
|
+
drop BACKEND UP 1
|
106
|
+
apache guinea UP 1
|
107
|
+
apache belem UP 1
|
108
|
+
apache BACKEND UP 1
|
109
|
+
static ngnix_downoi UP 1
|
110
|
+
static ngnix_petite UP 1
|
111
|
+
static ngnix_rindica UP 1
|
112
|
+
static nginx_stellatus UP 1
|
113
|
+
static nginx_belem UP 1
|
114
|
+
static nginx_petite DOWN 1
|
115
|
+
static apache_guinea UP 1
|
116
|
+
static BACKEND UP 6
|
117
|
+
ssh localhost UP 1
|
118
|
+
ssh BACKEND UP 1
|
119
|
+
|
120
|
+
./haproxyctl "show backends"
|
121
|
+
contact BACKEND UP 1
|
122
|
+
alpha BACKEND DOWN 0
|
123
|
+
sinatra BACKEND DOWN 0
|
124
|
+
python BACKEND UP 1
|
125
|
+
mobile BACKEND DOWN 0
|
126
|
+
ei BACKEND UP 1
|
127
|
+
showoff BACKEND UP 1
|
128
|
+
drop BACKEND UP 1
|
129
|
+
cheap BACKEND UP 1
|
130
|
+
apache BACKEND UP 1
|
131
|
+
static BACKEND UP 1
|
132
|
+
ssh BACKEND UP 1
|
133
|
+
</pre>
|
134
|
+
|
135
|
+
## Disable servers on the fly
|
136
|
+
<pre>
|
137
|
+
./haproxyctl "disable server static/nginx_belem"
|
138
|
+
|
139
|
+
./haproxyctl "show health" |grep nginx_belem
|
140
|
+
static nginx_belem MAINT 1
|
141
|
+
</pre>
|
142
|
+
## Graceful reloads
|
143
|
+
<pre>
|
144
|
+
./haproxyctl reload
|
145
|
+
gracefully stopping connections on pid 23162...
|
146
|
+
checking if connections still alive on 23162...
|
147
|
+
reloaded haproxy on pid 1119
|
148
|
+
</pre>
|
149
|
+
## Cloudkick/Nagios checks with graph-friendly output for queue size, total connections, etc
|
150
|
+
<pre>
|
151
|
+
./haproxyctl cloudkick
|
152
|
+
status ok haproxy is running
|
153
|
+
metric connections int 12
|
154
|
+
metric http_FRONTEND_request_rate int 45
|
155
|
+
metric http_FRONTEND_health_check_duration int 45
|
156
|
+
metric sinatra_sinatra_guinea_health_check_duration int 4
|
157
|
+
metric sinatra_BACKEND_health_check_duration int 4
|
158
|
+
metric mobile_sinatra_mobile_health_check_duration int 2
|
159
|
+
metric mobile_BACKEND_health_check_duration int 2
|
160
|
+
metric ei_guinea_health_check_duration int 4
|
161
|
+
metric ei_BACKEND_health_check_duration int 4
|
162
|
+
metric drop_guinea_total_requests gauge 1
|
163
|
+
metric drop_guinea_health_check_duration int 6
|
164
|
+
metric drop_BACKEND_total_requests gauge 1
|
165
|
+
metric drop_BACKEND_health_check_duration int 6
|
166
|
+
metric apache_guinea_health_check_duration int 41
|
167
|
+
metric apache_BACKEND_health_check_duration int 41
|
168
|
+
metric static_ngnix_downoi_total_requests gauge 472
|
169
|
+
metric static_ngnix_downoi_health_check_duration int 7
|
170
|
+
metric static_ngnix_petite_total_requests gauge 475
|
171
|
+
metric static_ngnix_petite_health_check_duration int 8
|
172
|
+
metric static_ngnix_rindica_total_requests gauge 457
|
173
|
+
metric static_ngnix_rindica_health_check_duration int 8
|
174
|
+
metric static_nginx_stellatus_total_requests gauge 470
|
175
|
+
metric static_nginx_stellatus_health_check_duration int 7
|
176
|
+
metric static_nginx_belem_total_requests gauge 460
|
177
|
+
metric static_nginx_belem_health_check_duration int 8
|
178
|
+
metric static_apache_guinea_total_requests gauge 449
|
179
|
+
metric static_apache_guinea_health_check_duration int 14
|
180
|
+
metric static_BACKEND_total_requests gauge 2783
|
181
|
+
metric static_BACKEND_health_check_duration int 45
|
182
|
+
</pre>
|
183
|
+
## does normal things like checks if a process is running before starting it...
|
184
|
+
<pre>
|
185
|
+
./haproxyctl start
|
186
|
+
./haproxyctl:35: haproxy is already running on pid 20317! (RuntimeError)
|
187
|
+
|
188
|
+
./haproxyctl restart
|
189
|
+
stopping existing haproxy on pid 20317...
|
190
|
+
waiting a ms...
|
191
|
+
checking if haproxy is still running...
|
192
|
+
starting haproxy...
|
193
|
+
done. running on pid 20348
|
194
|
+
</pre>
|
195
|
+
## keeps all the regular UNIX socket stuff
|
196
|
+
<pre>
|
197
|
+
./haproxyctl "show stat"
|
198
|
+
pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,
|
199
|
+
http,FRONTEND,,,3,82,2000,39585,47067637,12818945246,0,0,1465,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,59,,,,0,91460,13125,4115,305,73,,0,131,109078,,,
|
200
|
+
sinatra,sinatra_downoi,0,0,0,1,,791,452469,2258353,,0,,0,0,0,0,UP,1,1,0,60,13,304106,59545,,1,2,1,,791,,2,0,,1,L4OK,,46,0,736,0,40,15,0,0,,,,0,0,
|
201
|
+
sinatra,sinatra_rindica,0,0,0,1,,795,450488,2333534,,0,,0,0,3,1,UP,1,1,0,68,10,347679,52849,,1,2,2,,792,,2,0,,1,L4OK,,46,0,753,0,28,10,0,0,,,,0,0,
|
202
|
+
sinatra,sinatra_guinea,0,0,0,7,,638,360994,1046343,,0,,0,258,1,0,UP,1,1,0,4,4,1892969,72241,,1,2,3,,637,,2,0,,3,L4OK,,0,0,317,0,13,11,0,0,,,,0,0,
|
203
|
+
sinatra,BACKEND,0,0,0,7,0,2219,1263951,5638230,0,0,,0,299,4,1,UP,3,3,0,,0,2144680,0,,1,2,0,,2220,,1,0,,3,,,,0,1806,0,81,291,41,,,,,0,0,
|
204
|
+
ei,guinea,0,0,0,4,,3514,2067456,68408884,,0,,0,0,0,0,UP,1,1,0,6,1,2142278,70,,1,3,1,,3514,,2,0,,11,L4OK,,0,0,3060,323,131,0,0,0,,,,3,0,
|
205
|
+
ei,belem,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,0,1,28,7,259858,1274,,1,3,2,,0,,2,0,,0,L4OK,,43,0,0,0,0,0,0,0,,,,0,0,
|
206
|
+
ei,BACKEND,0,0,0,4,0,3514,2067456,68408884,0,0,,0,0,0,0,UP,1,1,1,,0,2144680,0,,1,3,0,,3514,,1,0,,11,,,,0,3060,323,131,0,0,,,,,3,0,
|
207
|
+
drop,guinea,0,0,0,2,,1042,634412,15327695,,0,,0,0,0,0,UP,1,1,0,5,1,2142277,70,,1,4,1,,1042,,2,0,,5,L4OK,,0,0,935,28,79,0,0,0,,,,2,0,
|
208
|
+
drop,belem,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,0,1,42,7,259855,958,,1,4,2,,0,,2,0,,0,L4OK,,44,0,0,0,0,0,0,0,,,,0,0,
|
209
|
+
drop,BACKEND,0,0,0,2,0,1042,634412,15327695,0,0,,0,0,0,0,UP,1,1,1,,0,2144680,0,,1,4,0,,1042,,1,0,,5,,,,0,935,28,79,0,0,,,,,2,0,
|
210
|
+
apache,guinea,0,0,0,3,,3781,3733003,19959026,,0,,0,0,0,0,UP,1,1,0,4,1,2142276,70,,1,5,1,,3781,,2,0,,5,L4OK,,0,0,3267,304,208,2,0,0,,,,2,0,
|
211
|
+
apache,belem,0,0,0,1,,1,379,528,,0,,0,0,0,0,UP,1,0,1,41,7,259854,1023,,1,5,2,,1,,2,0,,1,L4OK,,43,0,0,0,1,0,0,0,,,,0,0,
|
212
|
+
apache,BACKEND,0,0,0,3,0,3782,3733382,19959554,0,0,,0,0,0,0,UP,1,1,1,,0,2144680,0,,1,5,0,,3782,,1,0,,5,,,,0,3267,304,209,2,0,,,,,2,0,
|
213
|
+
static,ngnix_downoi,0,0,0,10,,12665,4970818,1883260969,,0,,0,4,25,5,UP,1,1,0,72,10,303928,61648,,1,6,1,,12640,,2,0,,10,L4OK,,46,0,10671,1656,307,0,0,0,,,,1167,4,
|
214
|
+
static,ngnix_petite,0,0,0,10,,13052,5141468,2033386644,,0,,1,5,13,3,UP,1,1,0,63,6,347401,11776,,1,6,2,,13039,,2,0,,10,L4OK,,46,0,10988,1694,352,0,0,0,,,,1223,4,
|
215
|
+
static,ngnix_rindica,0,0,0,10,,12736,5007655,2002399557,,0,,0,8,20,5,UP,1,1,0,64,10,347499,55375,,1,6,3,,12716,,2,0,,10,L4OK,,45,0,10736,1649,321,0,0,0,,,,1146,3,
|
216
|
+
static,nginx_stellatus,0,0,0,10,,15142,6017327,2194578425,,0,,0,7,0,0,UP,1,1,0,8,1,1555595,786,,1,6,4,,15142,,2,0,,10,L4OK,,42,0,12932,1844,364,0,0,0,,,,1253,8,
|
217
|
+
static,nginx_belem,0,0,0,10,,15227,6075157,2231761586,,0,,0,5,1,0,UP,1,1,0,10,1,1555573,787,,1,6,5,,15226,,2,0,,12,L4OK,,44,0,12981,1882,362,0,0,0,,,,1227,4,
|
218
|
+
static,nginx_petite,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,0,1,2144610,2144610,,1,6,6,,0,,2,0,,0,L4CON,,21000,0,0,0,0,0,0,0,,,,0,0,
|
219
|
+
static,apache_guinea,0,0,0,10,,24091,9895320,2263895160,,0,,0,0,0,0,UP,1,1,0,2,0,2144680,0,,1,6,7,,24091,,2,0,,100,L4OK,,0,0,20593,3038,459,0,0,0,,,,1241,0,
|
220
|
+
static,BACKEND,0,0,0,60,0,92841,37107745,12609282341,0,0,,1,29,59,13,UP,6,6,0,,0,2144680,0,,1,6,0,,92854,,1,0,,131,,,,0,78901,11763,2165,12,0,,,,,7257,23,
|
221
|
+
ssh,localhost,0,0,0,3,,122,54524,291662,,0,,0,0,0,0,UP,1,1,0,0,0,2144680,0,,1,7,1,,122,,2,0,,10,L4OK,,0,0,121,0,1,0,0,0,,,,0,0,
|
222
|
+
ssh,BACKEND,0,0,0,3,0,122,54524,291662,0,0,,0,0,0,0,UP,1,1,0,,0,2144680,0,,1,7,0,,122,,1,0,,10,,,,0,121,0,1,0,0,,,,,0,0,
|
223
|
+
</pre>
|
224
|
+
|
225
|
+
## More additions: Enables or disables a target server from every backend it appears.
|
226
|
+
<pre>
|
227
|
+
./haproxyctl "show health"
|
228
|
+
# pxname svname status weight
|
229
|
+
http FRONTEND OPEN
|
230
|
+
sinatra sinatra_downoi DOWN 1
|
231
|
+
sinatra sinatra_rindica DOWN 1
|
232
|
+
sinatra sinatra_guinea UP 1
|
233
|
+
sinatra BACKEND UP 1
|
234
|
+
ei guinea UP 1
|
235
|
+
ei BACKEND UP 1
|
236
|
+
drop guinea UP 1
|
237
|
+
drop BACKEND UP 1
|
238
|
+
apache guinea UP 1
|
239
|
+
apache BACKEND UP 1
|
240
|
+
static ngnix_downoi UP 1
|
241
|
+
static ngnix_petite UP 1
|
242
|
+
static ngnix_rindica UP 1
|
243
|
+
static nginx_stellatus UP 1
|
244
|
+
static nginx_belem UP 1
|
245
|
+
static nginx_petite MAINT 1
|
246
|
+
static apache_guinea UP 1
|
247
|
+
static BACKEND UP 6
|
248
|
+
ssh localhost UP 1
|
249
|
+
ssh BACKEND UP 1
|
250
|
+
|
251
|
+
|
252
|
+
./haproxyctl "disable all guinea"
|
253
|
+
./haproxyctl "show health"
|
254
|
+
pxname svname status weight
|
255
|
+
http FRONTEND OPEN
|
256
|
+
sinatra sinatra_downoi DOWN 1
|
257
|
+
sinatra sinatra_rindica DOWN 1
|
258
|
+
sinatra sinatra_guinea UP 1
|
259
|
+
sinatra BACKEND UP 1
|
260
|
+
ei guinea MAINT 1
|
261
|
+
ei BACKEND DOWN 0
|
262
|
+
drop guinea MAINT 1
|
263
|
+
drop BACKEND DOWN 0
|
264
|
+
apache guinea MAINT 1
|
265
|
+
apache BACKEND DOWN 0
|
266
|
+
static ngnix_downoi UP 1
|
267
|
+
static ngnix_petite UP 1
|
268
|
+
static ngnix_rindica UP 1
|
269
|
+
static nginx_stellatus UP 1
|
270
|
+
static nginx_belem UP 1
|
271
|
+
static nginx_petite UP 1
|
272
|
+
static apache_guinea UP 1
|
273
|
+
static BACKEND UP 1
|
274
|
+
ssh localhost UP 1
|
275
|
+
ssh BACKEND UP 1
|
276
|
+
</pre>
|
277
|
+
|
278
|
+
## Has an EXCEPT flag, too
|
279
|
+
<pre>
|
280
|
+
./haproxyctl "enable all EXCEPT apache_guinea"
|
281
|
+
./haproxyctl "show health"
|
282
|
+
pxname svname status weight
|
283
|
+
http FRONTEND OPEN
|
284
|
+
sinatra sinatra_downoi DOWN 1
|
285
|
+
sinatra sinatra_rindica DOWN 1
|
286
|
+
sinatra sinatra_guinea UP 1
|
287
|
+
sinatra BACKEND UP 1
|
288
|
+
ei guinea UP 1
|
289
|
+
ei BACKEND UP 1
|
290
|
+
drop guinea UP 1
|
291
|
+
drop BACKEND UP 1
|
292
|
+
apache guinea UP 1
|
293
|
+
apache BACKEND UP 1
|
294
|
+
static ngnix_downoi UP 1/2 1
|
295
|
+
static ngnix_petite UP 1/2 1
|
296
|
+
static ngnix_rindica UP 1/2 1
|
297
|
+
static nginx_stellatus UP 1/2 1
|
298
|
+
static nginx_belem UP 1/2 1
|
299
|
+
static nginx_petite UP 1/2 1
|
300
|
+
static apache_guinea UP 1
|
301
|
+
static BACKEND UP 7
|
302
|
+
ssh localhost UP 1
|
303
|
+
ssh BACKEND UP 1
|
304
|
+
</pre>
|
305
|
+
|
306
|
+
Contributors
|
307
|
+
------------
|
308
|
+
|
309
|
+
* Carlo Flores <github@petalphile.com> - Core Application
|
310
|
+
|
311
|
+
License
|
312
|
+
-----------------
|
313
|
+
|
314
|
+
This code is released under the MIT License. You should feel free to do whatever you want with it.
|
data/Rakefile
ADDED
data/bin/haproxyctl
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# HAProxy control script to start, stop, restart, configcheck, etc, as
|
4
|
+
# well as communicate to the stats socket.
|
5
|
+
#
|
6
|
+
# See https://github.com/flores/haproxyctl/README
|
7
|
+
#
|
8
|
+
# This line here is just for Redhat users who like "service haproxyctl blah"
|
9
|
+
# chkconfig: 2345 80 30
|
10
|
+
# description: HAProxy is a fast and reliable load balancer for UNIX systems
|
11
|
+
# HAProxyctl is an easy way to do init shit and talk to its stats socket
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'pathname'
|
15
|
+
lib = File.join(File.dirname(Pathname.new(__FILE__).realpath), '../lib')
|
16
|
+
$:.unshift lib unless $:.include?(lib)
|
17
|
+
|
18
|
+
require 'haproxyctl'
|
19
|
+
include HAProxyCTL
|
20
|
+
|
21
|
+
argument = ARGV.join(' ')
|
22
|
+
|
23
|
+
unless has_exec?
|
24
|
+
puts usage if argument =~ /help/ || ARGV.length < 1
|
25
|
+
|
26
|
+
raise "Cannot find haproxy executable. Please ensure it is in your $PATH, or set $HAPROXY_BIN environment variable."
|
27
|
+
end
|
28
|
+
|
29
|
+
display_usage! if argument =~ /help/ || ARGV.length < 1
|
30
|
+
|
31
|
+
begin
|
32
|
+
case argument
|
33
|
+
when "start"
|
34
|
+
if pidof
|
35
|
+
raise("haproxy is already running on pid #{pidof}!")
|
36
|
+
else
|
37
|
+
start
|
38
|
+
end
|
39
|
+
when "stop"
|
40
|
+
stop(check_running)
|
41
|
+
when "restart"
|
42
|
+
if pidof
|
43
|
+
stop(pidof)
|
44
|
+
stillpidof = check_running()
|
45
|
+
while stillpidof == pidof
|
46
|
+
puts "still haven't killed old pid. waiting 3s for existing connections to die... (ctrl+c to stop)"
|
47
|
+
sleep 3
|
48
|
+
stillpidof = check_running() || 0
|
49
|
+
end
|
50
|
+
start()
|
51
|
+
else
|
52
|
+
puts "haproxy was not running. starting..."
|
53
|
+
start()
|
54
|
+
end
|
55
|
+
when "reload"
|
56
|
+
if ( pidof )
|
57
|
+
reload(pidof)
|
58
|
+
else
|
59
|
+
puts "haproxy not running. starting..."
|
60
|
+
start()
|
61
|
+
end
|
62
|
+
when "status"
|
63
|
+
if ( pidof )
|
64
|
+
puts "haproxy is running on pid #{pidof}.\nthese ports are used and guys are connected:"
|
65
|
+
system("lsof -ln -i |awk \'$2 ~ /#{pidof}/ {print $8\" \"$9}\'")
|
66
|
+
else
|
67
|
+
puts "haproxy is not running"
|
68
|
+
end
|
69
|
+
when "configcheck"
|
70
|
+
puts `#{exec} -c -f #{config_path}`
|
71
|
+
when "nagios"
|
72
|
+
if ( pidof )
|
73
|
+
puts "OK"
|
74
|
+
exit
|
75
|
+
else
|
76
|
+
puts "CRITICAL: HAProxy is not running!"
|
77
|
+
exit(2)
|
78
|
+
end
|
79
|
+
when "cloudkick"
|
80
|
+
if ( pidof )
|
81
|
+
puts "status ok haproxy is running"
|
82
|
+
conn = `lsof -ln -i |grep -c #{pidof}`.chomp.to_i
|
83
|
+
# removes the listener
|
84
|
+
conn = conn - 1
|
85
|
+
puts "metric connections int #{conn}"
|
86
|
+
status=unixsock("show stat")
|
87
|
+
status.each do |line|
|
88
|
+
line = line.split(',')
|
89
|
+
if (line[0] !~ /^#/)
|
90
|
+
host = "#{line[0]}_#{line[1]}"
|
91
|
+
puts "metric #{host}_request_rate int #{line[47]}" if line[47].to_i > 0
|
92
|
+
puts "metric #{host}_total_requests gauge #{line[49]}" if line[49].to_i > 0
|
93
|
+
puts "metric #{host}_health_check_duration int #{line[35]}" if line[35].to_i > 0
|
94
|
+
puts "metric ${host}_current_queue int #{line[3]}" if line[3].to_i > 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
else
|
98
|
+
puts "status err haproxy is not running!"
|
99
|
+
end
|
100
|
+
when "show health"
|
101
|
+
status=unixsock("show stat")
|
102
|
+
status.each do |line|
|
103
|
+
data = line.split(',')
|
104
|
+
printf "%-30s %-30s %-7s %3s\n", data[0], data[1], data[17], data[18]
|
105
|
+
end
|
106
|
+
when /show backend(s?)/
|
107
|
+
status=unixsock("show stat").grep(/BACKEND/)
|
108
|
+
status.each do |line|
|
109
|
+
data = line.split(',')
|
110
|
+
printf "%-30s %-30s %-7s %3s\n", data[0], data[1], data[17], data[18]
|
111
|
+
end
|
112
|
+
when /disable all EXCEPT (.+)/
|
113
|
+
servername=$1
|
114
|
+
status=unixsock("show stat")
|
115
|
+
backend = status.grep(/#{servername}/)
|
116
|
+
backend.each do |line|
|
117
|
+
backend_group = line.split(',')
|
118
|
+
status.each do |pool|
|
119
|
+
data = pool.split(',')
|
120
|
+
if ( (data[0] == backend_group[0]) && ( data[1] !~ /#{servername}|BACKEND|FRONTEND/ ) && ( data[17] = 'UP' ) )
|
121
|
+
unixsock("disable server #{data[0]}/#{data[1]}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
when /disable all (.+)/
|
126
|
+
servername=$1
|
127
|
+
status=unixsock("show stat")
|
128
|
+
status.each do |line|
|
129
|
+
data = line.split(',')
|
130
|
+
if ( ( data[1] = servername ) && ( data[17] = 'UP' ) )
|
131
|
+
unixsock("disable server #{data[0]}/#{servername}")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
when /enable all EXCEPT (.+)/
|
135
|
+
servername=$1
|
136
|
+
status=unixsock("show stat")
|
137
|
+
backend = status.grep(/#{servername}/)
|
138
|
+
backend.each do |line|
|
139
|
+
backend_group = line.split(',')
|
140
|
+
status.each do |pool|
|
141
|
+
data = pool.split(',')
|
142
|
+
if ( (data[0] == backend_group[0]) && ( data[1] !~ /#{servername}|BACKEND|FRONTEND/ ) && ( data[17] =~ /Down|MAINT/i ) )
|
143
|
+
unixsock("enable server #{data[0]}/#{data[1]}")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
when /enable all (.+)/
|
148
|
+
servername=$1
|
149
|
+
status=unixsock("show stat")
|
150
|
+
status.each do |line|
|
151
|
+
data = line.split(',')
|
152
|
+
if ( ( data[1] = servername ) && ( data[17] =~ /Down|MAINT/i ) )
|
153
|
+
unixsock("enable server #{data[0]}/#{servername}")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
when 'version'
|
157
|
+
version
|
158
|
+
else
|
159
|
+
puts unixsock(argument)
|
160
|
+
end
|
161
|
+
rescue Errno::ENOENT => e
|
162
|
+
STDERR.puts e
|
163
|
+
exit 1
|
164
|
+
end
|