rhaproxy 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,590 @@
1
+ # = rhaproxy - A HAproxy gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/rhaproxy
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # class RhaproxyGlobal.new( array, str, array)
10
+ #
11
+
12
+ #
13
+ # Parameters in the "global" section are process-wide and often OS-specific. They
14
+ # are generally set once for all and do not need being changed once correct. Some
15
+ # of them have command-line equivalents.
16
+ #
17
+ class RhaproxyGlobal
18
+
19
+ #
20
+ # chroot <jail dir>
21
+ # Changes current directory to <jail dir> and performs a chroot() there before
22
+ # dropping privileges. This increases the security level in case an unknown
23
+ # vulnerability would be exploited, since it would make it very hard for the
24
+ # attacker to exploit the system. This only works when the process is started
25
+ # with superuser privileges. It is important to ensure that <jail_dir> is both
26
+ # empty and unwritable to anyone.
27
+ #
28
+ attr_accessor :chroot
29
+
30
+ #
31
+ # daemon
32
+ # Makes the process fork into background. This is the recommended mode of
33
+ # operation. It is equivalent to the command line "-D" argument. It can be
34
+ # disabled by the command line "-db" argument.
35
+ #
36
+ attr_accessor :daemon
37
+
38
+ #
39
+ # gid <number>
40
+ # Changes the process' group ID to <number>. It is recommended that the group
41
+ # ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
42
+ # be started with a user belonging to this group, or with superuser privileges.
43
+ # See also "group" and "uid".
44
+ #
45
+ attr_accessor :gid
46
+
47
+ #
48
+ # group <group name>
49
+ # Similar to "gid" but uses the GID of group name <group name> from /etc/group.
50
+ # See also "gid" and "user".
51
+ #
52
+ attr_accessor :group
53
+
54
+ #
55
+ # log <address> <facility> [max level [min level]]
56
+ # Adds a global syslog server. Up to two global servers can be defined. They
57
+ # will receive logs for startups and exits, as well as all logs from proxies
58
+ # configured with "log global".
59
+ #
60
+ # <address> can be one of:
61
+ #
62
+ # - An IPv4 address optionally followed by a colon and a UDP port. If
63
+ # no port is specified, 514 is used by default (the standard syslog
64
+ # port).
65
+ #
66
+ # - A filesystem path to a UNIX domain socket, keeping in mind
67
+ # considerations for chroot (be sure the path is accessible inside
68
+ # the chroot) and uid/gid (be sure the path is appropriately
69
+ # writeable).
70
+ #
71
+ # <facility> must be one of the 24 standard syslog facilities :
72
+ #
73
+ # kern user mail daemon auth syslog lpr news
74
+ # uucp cron auth2 ftp ntp audit alert cron2
75
+ # local0 local1 local2 local3 local4 local5 local6 local7
76
+ #
77
+ # An optional level can be specified to filter outgoing messages. By default,
78
+ # all messages are sent. If a maximum level is specified, only messages with a
79
+ # severity at least as important as this level will be sent. An optional minimum
80
+ # level can be specified. If it is set, logs emitted with a more severe level
81
+ # than this one will be capped to this level. This is used to avoid sending
82
+ # "emerg" messages on all terminals on some default syslog configurations.
83
+ # Eight levels are known :
84
+ #
85
+ # emerg alert crit err warning notice info debug
86
+ #
87
+ attr_accessor :log
88
+
89
+ #
90
+ # nbproc <number>
91
+ # Creates <number> processes when going daemon. This requires the "daemon"
92
+ # mode. By default, only one process is created, which is the recommended mode
93
+ # of operation. For systems limited to small sets of file descriptors per
94
+ # process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
95
+ # IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
96
+ #
97
+ attr_accessor :nbproc
98
+
99
+ #
100
+ # pidfile <pidfile>
101
+ # Writes pids of all daemons into file <pidfile>. This option is equivalent to
102
+ # the "-p" command line argument. The file must be accessible to the user
103
+ # starting the process. See also "daemon".
104
+ #
105
+ attr_accessor :pidfile
106
+
107
+ #
108
+ # uid <number>
109
+ # Changes the process' user ID to <number>. It is recommended that the user ID
110
+ # is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
111
+ # be started with superuser privileges in order to be able to switch to another
112
+ # one. See also "gid" and "user".
113
+ #
114
+ attr_accessor :uid
115
+
116
+ #
117
+ # ulimit-n <number>
118
+ # Sets the maximum number of per-process file-descriptors to <number>. By
119
+ # default, it is automatically computed, so it is recommended not to use this
120
+ # option.
121
+ #
122
+ attr_accessor :ulimit_n
123
+
124
+ #
125
+ # user <user name>
126
+ # Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
127
+ # See also "uid" and "group".
128
+ #
129
+ attr_accessor :user
130
+
131
+ #
132
+ # stats socket <path> [(uid | user) <uid>] [(gid | group) <gid>] [mode <mode>]
133
+ # [level <level>]
134
+ #
135
+ # Creates a UNIX socket in stream mode at location <path>. Any previously
136
+ # existing socket will be backed up then replaced. Connections to this socket
137
+ # will return various statistics outputs and even allow some commands to be
138
+ # issued. Please consult section 9.2 "Unix Socket commands" for more details.
139
+ #
140
+ # An optional "level" parameter can be specified to restrict the nature of
141
+ # the commands that can be issued on the socket :
142
+ # - "user" is the least privileged level ; only non-sensitive stats can be
143
+ # read, and no change is allowed. It would make sense on systems where it
144
+ # is not easy to restrict access to the socket.
145
+ #
146
+ # - "operator" is the default level and fits most common uses. All data can
147
+ # be read, and only non-sensible changes are permitted (eg: clear max
148
+ # counters).
149
+ #
150
+ # - "admin" should be used with care, as everything is permitted (eg: clear
151
+ # all counters).
152
+ #
153
+ # On platforms which support it, it is possible to restrict access to this
154
+ # socket by specifying numerical IDs after "uid" and "gid", or valid user and
155
+ # group names after the "user" and "group" keywords. It is also possible to
156
+ # restrict permissions on the socket by passing an octal value after the "mode"
157
+ # keyword (same syntax as chmod). Depending on the platform, the permissions on
158
+ # the socket will be inherited from the directory which hosts it, or from the
159
+ # user the process is started with.
160
+ #
161
+ attr_accessor :stats_socket
162
+
163
+ #
164
+ # stats timeout <timeout, in milliseconds>
165
+ # The default timeout on the stats socket is set to 10 seconds. It is possible
166
+ # to change this value with "stats timeout". The value must be passed in
167
+ # milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
168
+ #
169
+ attr_accessor :stats_timeout
170
+
171
+ #
172
+ # stats maxconn <connections>
173
+ # By default, the stats socket is limited to 10 concurrent connections. It is
174
+ # possible to change this value with "stats maxconn".
175
+ #
176
+ attr_accessor :stats_maxconn
177
+
178
+ #
179
+ # node <name>
180
+ # Only letters, digits, hyphen and underscore are allowed, like in DNS names.
181
+ #
182
+ # This statement is useful in HA configurations where two or more processes or
183
+ # servers share the same IP address. By setting a different node-name on all
184
+ # nodes, it becomes easy to immediately spot what server is handling the
185
+ # traffic.
186
+ #
187
+ attr_accessor :node
188
+
189
+ #
190
+ # description <text>
191
+ # Add a text that describes the instance.
192
+ #
193
+ # Please note that it is required to escape certain characters (# for example)
194
+ # and this text is inserted into a html page so you should avoid using
195
+ # "<" and ">" characters.
196
+ #
197
+ attr_accessor :description
198
+
199
+ #
200
+ # unix-bind [ prefix <prefix> ] [ mode <mode> ] [ user <user> ] [ uid <uid> ]
201
+ # [ group <group> ] [ gid <gid> ]
202
+ #
203
+ # Fixes common settings to UNIX listening sockets declared in "bind" statements.
204
+ # This is mainly used to simplify declaration of those UNIX sockets and reduce
205
+ # the risk of errors, since those settings are most commonly required but are
206
+ # also process-specific. The <prefix> setting can be used to force all socket
207
+ # path to be relative to that directory. This might be needed to access another
208
+ # component's chroot. Note that those paths are resolved before haproxy chroots
209
+ # itself, so they are absolute. The <mode>, <user>, <uid>, <group> and <gid>
210
+ # all have the same meaning as their homonyms used by the "bind" statement. If
211
+ # both are specified, the "bind" statement has priority, meaning that the
212
+ # "unix-bind" settings may be seen as process-wide default settings.
213
+ #
214
+ attr_accessor :unix_bind
215
+
216
+ #
217
+ # maxconn <number>
218
+ # Sets the maximum per-process number of concurrent connections to <number>. It
219
+ # is equivalent to the command-line argument "-n". Proxies will stop accepting
220
+ # connections when this limit is reached. The "ulimit-n" parameter is
221
+ # automatically adjusted according to this value. See also "ulimit-n".
222
+ #
223
+ attr_accessor :maxconn
224
+
225
+ #
226
+ # maxpipes <number>
227
+ # Sets the maximum per-process number of pipes to <number>. Currently, pipes
228
+ # are only used by kernel-based tcp splicing. Since a pipe contains two file
229
+ # descriptors, the "ulimit-n" value will be increased accordingly. The default
230
+ # value is maxconn/4, which seems to be more than enough for most heavy usages.
231
+ # The splice code dynamically allocates and releases pipes, and can fall back
232
+ # to standard copy, so setting this value too low may only impact performance.
233
+ #
234
+ attr_accessor :maxpipes
235
+
236
+ #
237
+ # noepoll
238
+ # Disables the use of the "epoll" event polling system on Linux. It is
239
+ # equivalent to the command-line argument "-de". The next polling system
240
+ # used will generally be "poll". See also "nosepoll", and "nopoll".
241
+ #
242
+ attr_accessor :noepoll
243
+
244
+ #
245
+ # nokqueue
246
+ # Disables the use of the "kqueue" event polling system on BSD. It is
247
+ # equivalent to the command-line argument "-dk". The next polling system
248
+ # used will generally be "poll". See also "nopoll".
249
+ #
250
+ attr_accessor :nokqueue
251
+
252
+ #
253
+ # nopoll
254
+ # Disables the use of the "poll" event polling system. It is equivalent to the
255
+ # command-line argument "-dp". The next polling system used will be "select".
256
+ # It should never be needed to disable "poll" since it's available on all
257
+ # platforms supported by HAProxy. See also "nosepoll", and "nopoll" and
258
+ # "nokqueue".
259
+ #
260
+ attr_accessor :nopoll
261
+
262
+ #
263
+ # nosepoll
264
+ # Disables the use of the "speculative epoll" event polling system on Linux. It
265
+ # is equivalent to the command-line argument "-ds". The next polling system
266
+ # used will generally be "epoll". See also "nosepoll", and "nopoll".
267
+ #
268
+ attr_accessor :nosepoll
269
+
270
+ #
271
+ # nosplice
272
+ # Disables the use of kernel tcp splicing between sockets on Linux. It is
273
+ # equivalent to the command line argument "-dS". Data will then be copied
274
+ # using conventional and more portable recv/send calls. Kernel tcp splicing is
275
+ # limited to some very recent instances of kernel 2.6. Most versions between
276
+ # 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not
277
+ # be used. This option makes it easier to globally disable kernel splicing in
278
+ # case of doubt. See also "option splice-auto", "option splice-request" and
279
+ # "option splice-response".
280
+ #
281
+ attr_accessor :nosplice
282
+
283
+ #
284
+ # spread-checks <0..50, in percent>
285
+ # Sometimes it is desirable to avoid sending health checks to servers at exact
286
+ # intervals, for instance when many logical servers are located on the same
287
+ # physical server. With the help of this parameter, it becomes possible to add
288
+ # some randomness in the check interval between 0 and +/- 50%. A value between
289
+ # 2 and 5 seems to show good results. The default value remains at 0.
290
+ #
291
+ attr_accessor :spread_checks
292
+
293
+ #
294
+ # tune.bufsize <number>
295
+ # Sets the buffer size to this size (in bytes). Lower values allow more
296
+ # sessions to coexist in the same amount of RAM, and higher values allow some
297
+ # applications with very large cookies to work. The default value is 16384 and
298
+ # can be changed at build time. It is strongly recommended not to change this
299
+ # from the default value, as very low values will break some services such as
300
+ # statistics, and values larger than default size will increase memory usage,
301
+ # possibly causing the system to run out of memory. At least the global maxconn
302
+ # parameter should be decreased by the same factor as this one is increased.
303
+ #
304
+ attr_accessor :tune_bufsize
305
+
306
+ #
307
+ # tune.chksize <number>
308
+ # Sets the check buffer size to this size (in bytes). Higher values may help
309
+ # find string or regex patterns in very large pages, though doing so may imply
310
+ # more memory and CPU usage. The default value is 16384 and can be changed at
311
+ # build time. It is not recommended to change this value, but to use better
312
+ # checks whenever possible.
313
+ #
314
+ attr_accessor :tune_chksize
315
+
316
+ #
317
+ # tune.maxaccept <number>
318
+ # Sets the maximum number of consecutive accepts that a process may perform on
319
+ # a single wake up. High values give higher priority to high connection rates,
320
+ # while lower values give higher priority to already established connections.
321
+ # This value is limited to 100 by default in single process mode. However, in
322
+ # multi-process mode (nbproc > 1), it defaults to 8 so that when one process
323
+ # wakes up, it does not take all incoming connections for itself and leaves a
324
+ # part of them to other processes. Setting this value to -1 completely disables
325
+ # the limitation. It should normally not be needed to tweak this value.
326
+ #
327
+ attr_accessor :tune_maxaccept
328
+
329
+ #
330
+ # tune.maxpollevents <number>
331
+ # Sets the maximum amount of events that can be processed at once in a call to
332
+ # the polling system. The default value is adapted to the operating system. It
333
+ # has been noticed that reducing it below 200 tends to slightly decrease
334
+ # latency at the expense of network bandwidth, and increasing it above 200
335
+ # tends to trade latency for slightly increased bandwidth.
336
+ #
337
+ attr_accessor :tune_maxpollevents
338
+
339
+ #
340
+ # tune.maxrewrite <number>
341
+ # Sets the reserved buffer space to this size in bytes. The reserved space is
342
+ # used for header rewriting or appending. The first reads on sockets will never
343
+ # fill more than bufsize-maxrewrite. Historically it has defaulted to half of
344
+ # bufsize, though that does not make much sense since there are rarely large
345
+ # numbers of headers to add. Setting it too high prevents processing of large
346
+ # requests or responses. Setting it too low prevents addition of new headers
347
+ # to already large requests or to POST requests. It is generally wise to set it
348
+ # to about 1024. It is automatically readjusted to half of bufsize if it is
349
+ # larger than that. This means you don't have to worry about it when changing
350
+ # bufsize.
351
+ #
352
+ attr_accessor :tune_maxrewrite
353
+
354
+ # tune.rcvbuf.client <number>
355
+ # Forces the kernel socket receive buffer size on the client or the server side
356
+ # to the specified value in bytes. This value applies to all TCP/HTTP frontends
357
+ # and backends. It should normally never be set, and the default size (0) lets
358
+ # the kernel autotune this value depending on the amount of available memory.
359
+ # However it can sometimes help to set it to very low values (eg: 4096) in
360
+ # order to save kernel memory by preventing it from buffering too large amounts
361
+ # of received data. Lower values will significantly increase CPU usage though.
362
+ #
363
+ attr_accessor :tune_rcvbuf_client
364
+
365
+ # tune.rcvbuf.server <number>
366
+ # Forces the kernel socket receive buffer size on the client or the server side
367
+ # to the specified value in bytes. This value applies to all TCP/HTTP frontends
368
+ # and backends. It should normally never be set, and the default size (0) lets
369
+ # the kernel autotune this value depending on the amount of available memory.
370
+ # However it can sometimes help to set it to very low values (eg: 4096) in
371
+ # order to save kernel memory by preventing it from buffering too large amounts
372
+ # of received data. Lower values will significantly increase CPU usage though.
373
+ #
374
+ attr_accessor :tune_rcvbuf_server
375
+
376
+ #
377
+ # tune.sndbuf.client <number>
378
+ # Forces the kernel socket send buffer size on the client or the server side to
379
+ # the specified value in bytes. This value applies to all TCP/HTTP frontends
380
+ # and backends. It should normally never be set, and the default size (0) lets
381
+ # the kernel autotune this value depending on the amount of available memory.
382
+ # However it can sometimes help to set it to very low values (eg: 4096) in
383
+ # order to save kernel memory by preventing it from buffering too large amounts
384
+ # of received data. Lower values will significantly increase CPU usage though.
385
+ # Another use case is to prevent write timeouts with extremely slow clients due
386
+ # to the kernel waiting for a large part of the buffer to be read before
387
+ # notifying haproxy again.
388
+ #
389
+ attr_accessor :tune_sndbuf_client
390
+
391
+ #
392
+ # tune.sndbuf.server <number>
393
+ # Forces the kernel socket send buffer size on the client or the server side to
394
+ # the specified value in bytes. This value applies to all TCP/HTTP frontends
395
+ # and backends. It should normally never be set, and the default size (0) lets
396
+ # the kernel autotune this value depending on the amount of available memory.
397
+ # However it can sometimes help to set it to very low values (eg: 4096) in
398
+ # order to save kernel memory by preventing it from buffering too large amounts
399
+ # of received data. Lower values will significantly increase CPU usage though.
400
+ # Another use case is to prevent write timeouts with extremely slow clients due
401
+ # to the kernel waiting for a large part of the buffer to be read before
402
+ # notifying haproxy again.
403
+ #
404
+ attr_accessor :tune_sndbuf_server
405
+
406
+ #
407
+ # debug
408
+ # Enables debug mode which dumps to stdout all exchanges, and disables forking
409
+ # into background. It is the equivalent of the command-line argument "-d". It
410
+ # should never be used in a production configuration since it may prevent full
411
+ # system startup.
412
+ #
413
+ attr_accessor :debug
414
+
415
+ #
416
+ # quiet
417
+ # Do not display any message during startup. It is equivalent to the command-
418
+ # line argument "-q".
419
+ #
420
+ attr_accessor :quiet
421
+
422
+ #
423
+ # Returns a new RhaproxyGlobal Object
424
+ #
425
+ def initialize()
426
+ end
427
+
428
+ #
429
+ # Compile the HAproxy global configuration
430
+ #
431
+ def config
432
+
433
+ conf = option_string()
434
+
435
+ return conf
436
+
437
+ end
438
+
439
+ private
440
+
441
+ def option_string()
442
+
443
+ ostring = " " + "global " + "\n"
444
+
445
+ if @chroot
446
+ ostring += " " + "chroot " + @chroot.to_s + "\n"
447
+ end
448
+
449
+ if @daemon
450
+ ostring += " " + "daemon " + "\n"
451
+ end
452
+
453
+ if @gid
454
+ ostring += " " + "gid " + @gid.to_s + "\n"
455
+ end
456
+
457
+ if @group
458
+ ostring += " " + "group " + @group.to_s + "\n"
459
+ end
460
+
461
+ if @log
462
+ ostring += " " + "log " + @log.to_s + "\n"
463
+ end
464
+
465
+ if @nbproc
466
+ ostring += " " + "nbproc " + @nbproc.to_s + "\n"
467
+ end
468
+
469
+ if @pidfile
470
+ ostring += " " + "pidfile " + @pidfile.to_s + "\n"
471
+ end
472
+
473
+ if @uid
474
+ ostring += " " + "uid " + @uid.to_s + "\n"
475
+ end
476
+
477
+ if @ulimit_n
478
+ ostring += " " + "ulimit-n " + @ulimit_n.to_s + "\n"
479
+ end
480
+
481
+ if @user
482
+ ostring += " " + "user " + @user.to_s + "\n"
483
+ end
484
+
485
+ if @stats_socket
486
+ ostring += " " + "stats socket " + @stats_socket.to_s + "\n"
487
+ end
488
+
489
+ if @stats_timeout
490
+ ostring += " " + "stats timeout " + @stats_timeout.to_s + "\n"
491
+ end
492
+
493
+ if @stats_maxconn
494
+ ostring += " " + "stats maxconn " + @stats_maxconn.to_s + "\n"
495
+ end
496
+
497
+ if @node
498
+ ostring += " " + "node " + @node.to_s + "\n"
499
+ end
500
+
501
+ if @description
502
+ ostring += " " + "description " + @description.to_s + "\n"
503
+ end
504
+
505
+ if @unix_bind
506
+ ostring += " " + "unix-bind " + @unix_bind.to_s + "\n"
507
+ end
508
+
509
+ if @maxconn
510
+ ostring += " " + "maxconn " + @maxconn.to_s + "\n"
511
+ end
512
+
513
+ if @maxpipes
514
+ ostring += " " + "maxpipes " + @maxpipes.to_s + "\n"
515
+ end
516
+
517
+ if @noepoll
518
+ ostring += " " + "noepoll " + "\n"
519
+ end
520
+
521
+ if @nokqueue
522
+ ostring += " " + "nokqueue " + "\n"
523
+ end
524
+
525
+ if @nopoll
526
+ ostring += " " + "nopoll " + "\n"
527
+ end
528
+
529
+ if @nosepoll
530
+ ostring += " " + "nosepoll " + "\n"
531
+ end
532
+
533
+ if @nosplice
534
+ ostring += " " + "nosplice " + "\n"
535
+ end
536
+
537
+ if @spread_checks
538
+ ostring += " " + "spread-checks " + @spread_checks.to_s + "\n"
539
+ end
540
+
541
+ if @tune_bufsize
542
+ ostring += " " + "tune.bufsize " + @tune_bufsize.to_s + "\n"
543
+ end
544
+
545
+ if @tune_chksize
546
+ ostring += " " + "tune.chksize " + @tune_chksize.to_s + "\n"
547
+ end
548
+
549
+ if @tune_maxaccept
550
+ ostring += " " + "tune.maxaccept " + @tune_maxaccept.to_s + "\n"
551
+ end
552
+
553
+ if @tune_maxpollevents
554
+ ostring += " " + "tune.maxpollevents " + @tune_maxpollevents.to_s + "\n"
555
+ end
556
+
557
+ if @tune_maxrewrite
558
+ ostring += " " + "tune.maxrewrite " + @tune_maxrewrite.to_s + "\n"
559
+ end
560
+
561
+ if @tune_rcvbuf_client
562
+ ostring += " " + "tune.rcvbuf.client " + @tune_rcvbuf_client.to_s + "\n"
563
+ end
564
+
565
+ if @tune_rcvbuf_server
566
+ ostring += " " + "tune.rcvbuf.server " + @tune_rcvbuf_server.to_s + "\n"
567
+ end
568
+
569
+ if @tune_sndbuf_client
570
+ ostring += " " + "tune.sndbuf.client " + @tune_sndbuf_client.to_s + "\n"
571
+ end
572
+
573
+ if @tune_sndbuf_server
574
+ ostring += " " + "tune.sndbuf.server " + @tune_sndbuf_server.to_s + "\n"
575
+ end
576
+
577
+ if @debug
578
+ ostring += " " + "debug " + "\n"
579
+ end
580
+
581
+ if @quiet
582
+ ostring += " " + "quiet " + "\n"
583
+ end
584
+
585
+ ostring += "\n"
586
+
587
+ return ostring
588
+ end
589
+ end
590
+