-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsdirectord.pl
5125 lines (4369 loc) · 138 KB
/
nsdirectord.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
81
82
83
84
85
86
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
######################################################################
# nsdirectord http://www.vergenet.net/linux/ldirectord/
# Linux Director Daemon - run "perldoc ldirectord" for details
#
# 1999-2006 (C) Jacob Rief <[email protected]>,
# Horms <[email protected]> and others
#
# License: GNU General Public License (GPL)
#
# Note: * The original author of this software was Jacob Rief circa 1999
# * It was maintained by Jacob Rief and Horms
# from November 1999 to July 2003.
# * From July 2003 Horms is the maintainer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
#
######################################################################
# A Brief history of versions:
#
# From oldest to newest
# 1.1-1.144: ldirecord maintained in CVS HEAD branch
# 1.145-1.186: ldirectord.in maintained in CVS HEAD BRANCH
# 1.186-ha-VERSION: ldirectord.in maintained in mercurial
=head1 NAME
ldirectord - Linux Director Daemon
Daemon to monitor remote services and control Linux Virtual Server
=head1 SYNOPSIS
B<ldirectord> [B<-d|--debug>] [--] [I<configfile>]
B<start> | B<stop> | B<restart> | B<try-restart> | B<reload> | B<force-reload> | B<status>
B<ldirectord> [B<-h|-?|--help|-v|--version>]
=head1 DESCRIPTION
B<ldirectord> is a daemon to monitor and administer real servers in a
cluster of load balanced virtual servers. B<ldirectord> typically is
started from heartbeat but can also be run from the command line. On
startup B<ldirectord> reads the file B</usr/etc/ha.d/conf/>I<configuration>.
After parsing the file, entries for virtual servers are created on the LVS.
Now at regular intervals the specified real servers are monitored and if
they are considered alive, added to a list for each virtual server. If a
real server fails, it is removed from that list. Only one instance of
B<ldirectord> can be started for each configuration, but more instances of
B<ldirectord> may be started for different configurations. This helps to
group clusters of services. Normally one would put an entry inside
B</usr/etc/ha.d/haresources>
I<nodename virtual-ip-address ldirectord::configuration>
to start ldirectord from heartbeat.
=head1 OPTIONS
I<configuration>:
This is the name for the configuration as specified in the file
B</usr/etc/ha.d/conf/>I<configuration>
B<-d|--debug> Don't start as daemon and log verbosely.
B<-h|--help> Print user manual and exit.
B<-v|--version> Print version and exit.
B<start> the daemon for the specified configuration.
B<stop> the daemon for the specified configuration. This is the same as sending
a TERM signal to the running daemon.
B<restart> the daemon for the specified configuration. The same as stopping and starting.
B<reload> the configuration file. This is only useful for modifications
inside a virtual server entry. It will have no effect on adding or
removing a virtual server block. This is the same as sending a HUP signal to
the running daemon.
B<status> of the running daemon for the specified configuration.
=head1 SYNTAX
=head2 Description of how to write configuration files
B<virtual = >I<(ip_address|hostname:portnumber|servicename)|firewall-mark>
Defines a virtual service by IP-address (or hostname) and port (or
servicename) or firewall-mark. A firewall-mark is an integer greater than
zero. The configuration of marking packets is controlled using the C<-m>
option to B<ipchains>(8). All real services and flags for a virtual
service must follow this line immediately and be indented.
B<checktimeout = >I<n>
Timeout in seconds for connect, external, external-perl and ping checks. If the timeout is
exceeded then the real server is declared dead.
If defined in a virtual server section then the global value is overridden.
If undefined then the value of negotiatetimeout is used. negotiatetimeout
is also a global value that may be overridden by a per-virtual setting.
If both checktimeout and negotiatetimeout are unset, the default is used.
Default: 5 seconds
B<negotiatetimeout = >I<n>
Timeout in seconds for negotiate checks.
If defined in a virtual server section then the global value is overridden.
If undefined then the value of connecttimeout is used. connecttimeout is
also a global value that may be overridden by a per-virtual setting.
If both negotiatetimeout and connecttimeout are unset, the default is used.
Default: 30 seconds
B<checkinterval = >I<n>
Defines the number of second between server checks.
When fork=no this option defines the amount of time ldirectord sleeps
between running all of the realserver checks in all virtual service pools.
When fork=yes this option defines the amount of time each forked child
sleeps per virtual service pool after running all realserver checks for
that pool.
If set in the virtual server section then the global value is overridden,
but ONLY if using forking mode (B<fork = >I<yes>).
Default: 10 seconds
B<checkcount = >I<n>
This option is deprecated and slated for removal in a future version.
Please see the 'failurecount' option.
The number of times a check will be attempted before it is considered to
have failed. Only works with ping checks. Note that the
checktimeout/negotiatetimeout is additive, so if a connect check is used,
checkcount is 3 and checktimeout is 2 seconds, then a total of 6 seconds
worth of timeout will occur before the check fails.
If defined in a virtual server section then the global value is overridden.
Default: 1
B<failurecount = >I<n>
The number of consecutive times a failure will have to be reported by a
check before the realserver is considered to have failed. A
value of 1 will have the realserver considered failed on the first failure.
A successful check will reset the failure counter to 0.
If defined in a virtual server section then the global value is overridden.
Default: 1
B<autoreload = >B<yes> | B<no>
Defines if <ldirectord> should continuously check the configuration file
for modification. If this is set to 'yes' and the configuration file
changed on disk and its modification time (mtime) is newer than the
previous version, the configuration is automatically reloaded.
Default: no
B<callback = ">I</path/to/callback>B<">
If this directive is defined, B<ldirectord> automatically calls
the executable I</path/to/callback> after the configuration
file has changed on disk. This is useful to update the configuration
file through B<scp> on the other heartbeated host. The first argument
to the callback is the name of the configuration.
This directive might also be used to restart B<ldirectord> automatically
after the configuration file changed on disk. However, if B<autoreload>
is set to yes, the configuration is reloaded anyway.
B<fallback = >I<ip_address|hostname[:portnumber|sercvicename]> [B<gate> | B<masq> | B<ipip>]
the server onto which a webservice is redirected if all real
servers are down. Typically this would be 127.0.0.1 with
an emergency page.
If defined in a virtual server section then the global value is overridden.
B<fallbackcommand = ">I<path to script>B<">
If this directive is defined, the supplied script is executed whenever all
real servers for a virtual service are down or when the first real server
comes up again. In the first case, it is called with "start" as its first
argument, in the latter with "stop".
If defined in a virtual server section then the global value is overridden.
B<logfile = ">I</path/to/logfile>B<">|syslog_facility
An alternative logfile might be specified with this directive. If the logfile
does not have a leading '/', it is assumed to be a syslog(3) facility name.
Default: log directly to the file I</var/log/ldirectord.log>.
B<emailalert = ">I<emailaddress>[, I<emailaddress>]...B<">
A valid email address for sending alerts about the changed connection status
to any real server defined in the virtual service. This option requires
perl module MailTools to be installed. Automatically tries to send email
using any of the built-in methods. See perldoc Mail::Mailer for more info on
methods.
Multiple addresses may be supplied, comma delimited.
If defined in a virtual server section then the global value is overridden.
B<emailalertfrom = >I<emailaddress>
A valid email address to use as the from address of the email alerts. You
can use a plain email address or any RFC-compliant string for the From header
in the body of an email message (such as: "ldirectord Alerts" <[email protected]>)
Do not quote this string unless you want the quotes passed in as part of the
From header.
Default: unset, take system generated default (probably root@hostname)
B<emailalertfreq => I<n>
Delay in seconds between repeating email alerts while any given real server
in the virtual service remains inaccessible. A setting of zero seconds
will inhibit the repeating alerts. The email timing accuracy of this
setting is dependent on the number of seconds defined in the checkinterval
configuration option.
If defined in a virtual server section then the global value is overridden.
Default: 0
B<emailalertstatus = >B<all> | B<none> | B<starting> | B<running> | B<stopping> | B<reloading>,...
Comma delimited list of server states in which email alerts should be sent.
B<all> is a short-hand for
"B<starting>,B<running>,B<stopping>,B<reloading>". If B<none> is
specified, no other option may be specified, otherwise options are ored
with each other.
If defined in a virtual server section then the global value is overridden.
Default: all
B<smtp = >I<ip_address|hostname>B<">
A valid SMTP server address to use for sending email via SMTP.
If defined in a virtual server section then the global value is overridden.
B<execute = ">I<configuration>B<">
Use this directive to start an instance of ldirectord for
the named I<configuration>.
B<supervised = >B<yes> | B<no>
If I<yes>, then ldirectord does not go into background mode.
All log-messages are redirected to stdout instead of a logfile.
This is useful to run B<ldirectord> supervised from daemontools.
See http://untroubled.org/rpms/daemontools/ or http://cr.yp.to/daemontools.html
for details.
Default: I<no>
B<fork = >B<yes> | B<no>
If I<yes>, then ldirectord will spawn a child process for every virtual server,
and run checks against the real servers from them. This will increase response
times to changes in real server status in configurations with many virtual
servers. This may also use less memory then running many separate instances of
ldirectord. Child processes will be automatically restarted if they die.
Default: I<no>
B<quiescent = >B<yes> | B<no>
If I<yes>, then when real or failback servers are determined
to be down, they are not actually removed from the kernel's LVS
table. Rather, their weight is set to zero which means that no
new connections will be accepted.
This has the side effect, that if the real server has persistent
connections, new connections from any existing clients will continue to be
routed to the real server, until the persistent timeout can expire. See
L<ipvsadm> for more information on persistent connections.
This side-effect can be avoided by running the following:
echo 1 > /proc/sys/net/ipv4/vs/expire_quiescent_template
If the proc file isn't present this probably means that
the kernel doesn't have LVS support, LVS support isn't loaded,
or the kernel is too old to have the proc file. Running
ipvsadm as root should load LVS into the kernel if it is possible.
If I<no>, then the real or failback servers will be removed
from the kernel's LVS table. The default is I<yes>.
If defined in a virtual server section then the global value is overridden.
Default: I<yes>
B<cleanstop = >B<yes> | B<no>
If I<yes>, then when ldirectord exits it will remove all of the virtual
server pools that it is managing from the kernel's LVS table.
If I<no>, then the virtual server pools it is managing and any real
or failback servers listed in them at the time ldirectord exits will
be left as-is. If you want to be able to stop ldirectord without having
traffic to your realservers interrupted you will want to set this to I<no>.
If defined in a virtual server section then the global value is overridden.
Default: I<yes>
B<maintenancedir = >I<directoryname>
If this option is set ldirectord will look for a special file in the specified
directory and, if found, force the status of the real server identified by the
file to down, skipping the normal health check. This would be useful if you
wish to force servers down for maintenance without having to modify the actual
ldirectord configuration file.
For example, given a realserver with IP 172.16.1.2, service on port 4444, and
a resolvable reverse DNS entry pointing to "realserver2.example.com" ldirectord
will check for the existence of the following files:
=over
=item 172.16.1.2:4444
=item 172.16.1.2
=item realserver2.example.com:4444
=item realserver2.example.com
=item realserver2:4444
=item realserver2
=back
If any one of those files is found then ldirectord will immediately force the
status of the server to down as if the check had failed.
Note: Since it checks for the IP/hostname without the port this means you can
decide to place an entire realserver into maintenance across a large number of
virtual service pools with a single file (if you were going to reboot the server,
for instance) or include the port number and put just a particular service into
maintenance.
This option is not valid in a virtual server section.
Default: disabled
=head2 Section virtual
The following commands must follow a B<virtual> entry and must be indented
with a minimum of 4 spaces or one tab.
B<real => I<ip_address|hostname[-E<gt>ip_address|hostname][:portnumber|servicename>] B<gate> | B<masq> | B<ipip> [I<weight>] [B<">I<request>B<", ">I<receive>B<">]
Defines a real service by IP-address (or hostname) and port (or
servicename). If the port is omitted then a 0 will be used, this is
intended primarily for fwmark services where the port for real servers is
ignored. Optionally a range of IPv4 addresses (or two hostnames) may be
given, in which case each IPv4 address in the range will be treated as a real
server using the given port. The second argument defines the forwarding
method, must be B<gate>, B<ipip> or B<masq>. The third argument is
optional and defines the weight for that real server. If omitted then a
weight of 1 will be used. The last two arguments are also optional. They
define a request-receive pair to be used to check if a server is alive.
They override the request-receive pair in the virtual server section. These
two strings must be quoted. If the request string starts with I<http://...>
the IP-address and port of the real server is overridden, otherwise the
IP-address and port of the real server is used.
=head2
For TCP and UDP (non fwmark) virtual services, unless the forwarding method
is B<masq> and the IP address of a real server is non-local (not present on
a interface on the host running ldirectord) then the port of the real
server will be set to that of its virtual service. That is, port-mapping is
only available to if the real server is another machine and the forwarding
method is B<masq>. This is due to the way that the underlying LVS code in
the kernel functions.
=head2
More than one of these entries may be inside a virtual section. The
checktimeout, negotiatetimeout, checkcount, fallback, emailalert,
emailalertfreq and quiescent options listed above may also appear inside a
virtual section, in which case the global setting is overridden.
B<checktype =
>B<connect> | B<external> | B<external-perl> | B<negotiate> | B<off> | B<on> | B<ping> | B<checktimeout>I<N>
Type of check to perform. Negotiate sends a request and matches a receive
string. Connect only attempts to make a TCP/IP connection, thus the
request and receive strings may be omitted. If checktype is a number then
negotiate and connect is combined so that after each N connect attempts one
negotiate attempt is performed. This is useful to check often if a service
answers and in much longer intervals a negotiating check is done. Ping
means that ICMP ping will be used to test the availability of real servers.
Ping is also used as the connect check for UDP services. Off means no
checking will take place and no real or fallback servers will be activated.
On means no checking will take place and real servers will always be
activated. Default is I<negotiate>.
B<service = >B<dns> | B<ftp> | B<http> | B<https> | B<http_proxy> | B<imap> | B<imaps> | B<ldap> | B<mysql> | B<nntp> | B<none> | B<oracle> | B<pgsql> | B<pop> | B<pops> | B<radius> | B<simpletcp> | B<sip> | B<smtp> | B<submission>
The type of service to monitor when using checktype=negotiate. None denotes
a service that will not be monitored.
simpletcp sends the B<request> string to the server and tests it against
the B<receive> regexp. The other types of checks connect to the server
using the specified protocol. Please see the B<request> and B<receive>
sections for protocol specific information.
Default:
=over 4
=item * Virtual server port is 21: ftp
=item * Virtual server port is 25: smtp
=item * Virtual server port is 53: dns
=item * Virtual server port is 80: http
=item * Virtual server port is 110: pop
=item * Virtual server port is 119: nntp
=item * Virtual server port is 143: imap
=item * Virtual server port is 389: ldap
=item * Virtual server port is 443: https
=item * Virtual server port is 587: submission
=item * Virtual server port is 993: imaps
=item * Virtual server port is 995: pops
=item * Virtual server port is 1521: oracle
=item * Virtual server port is 1812: radius
=item * Virtual server port is 3128: http_proxy
=item * Virtual server port is 3306: mysql
=item * Virtual server port is 5432: pgsql
=item * Virtual server port is 5060: sip
=item * Otherwise: none
=back
B<checkcommand = ">I<path to script>B<">
This setting is used if checktype is external or external-perl and is the command to be run
to check the status of a real server. It should exit with status 0 if
everything is ok, or non-zero otherwise.
Four parameters are passed to the script:
=over 4
=item * virtual server ip/firewall mark
=item * virtual server port
=item * real server ip
=item * real server port
=back
If the checktype is external-perl then the command is assumed to be a
Perl script and it is evaluated into an anonymous subroutine which is
called at check time, avoiding a fork-exec. The argument signature and
exit code conventions are identical to checktype external. That is, an
external-perl checktype should also work as an external checktype.
Default: /bin/true
B<checkport = >I<n>
Number of port to monitor. Sometimes check port differs from service port.
Default: port specified for each real server
B<request = ">I<uri to requested object>B<">
This object will be requested each checkinterval seconds on each real
server. The string must be inside quotes. Note that this string may be
overridden by an optional per real-server based request-string.
For an HTTP/HTTPS check, this should be a relative URI, while it has to
be absolute for the 'http_proxy' check type. In the latter case, this
URI will be requested through the proxy backend that is being checked.
For a DNS check this should the name of an A record, or the address
of a PTR record to look up.
For a MySQL, Oracle or PostgeSQL check, this should be an SQL SELECT query.
The data returned is not checked, only that the
answer is one or more rows. This is a required setting.
For a simpletcp check, this string is sent verbatim except any occurrences
of \n are replaced with a new line character.
B<receive = ">I<regexp to compare>B<">
If the requested result contains this I<regexp to compare>, the real server
is declared alive. The regexp must be inside quotes. Keep in mind that
regexps are not plain strings and that you need to escape the special
characters if they should as literals. Note that this regexp may be
overridden by an optional per real-server based receive regexp.
For a DNS check this should be any one the A record's addresses or
any one of the PTR record's names.
For a MySQL check, the receive setting is not used.
B<httpmethod = GET> | B<HEAD>
Sets the HTTP method which should be used to fetch the URI specified in
the request-string. GET is the method used by default if the parameter is
not set. If HEAD is used, the receive-string should be unset.
Default: GET
B<virtualhost = ">I<hostname>B<">
Used when using a negotiate check with HTTP or HTTPS. Sets the host header
used in the HTTP request. In the case of HTTPS this generally needs to
match the common name of the SSL certificate. If not set then the host
header will be derived from the request url for the real server if present.
As a last resort the IP address of the real server will be used.
B<login = ">I<username>B<">
For FTP, IMAP, LDAP, MySQL, Oracle, POP and PostgreSQL, the username
used to log in.
For Radius the passwd is used for the attribute User-Name.
For SIP, the username is used as both the to and from address for an
OPTIONS query.
Default:
=over 4
=item * FTP: Anonymous
=item * MySQL Oracle, and PostgreSQL: Must be specified in the configuration
=item * SIP: ldirectord\@<hostname>, hostname is derived as per the passwd
option below.
=item * Otherwise: empty string, which denotes that
case authentication will not be attempted.
=back
B<passwd = ">I<password>B<">
Password to use to login to FTP, IMAP, LDAP, MySQL, Oracle, POP, PostgreSQL
and SIP servers.
For Radius the passwd is used for the attribute User-Password.
Default:
=over 4
=item * FTP: ldirectord\@<hostname>,
where hostname is the environment variable HOSTNAME evaluated at
run time, or sourced from uname if unset.
=item * Otherwise: empty string.
In the case of LDAP, MySQL, Oracle, and PostgreSQL this means
that authentication will not be performed.
=back
B<database = ">I<databasename>B<">
Database to use for MySQL, Oracle and PostgreSQL servers, this is the
database that the query (set by B<receive> above) will be performed
against. This is a required setting.
B<secret = ">I<radiussecret>B<">
Secret to use for Radius servers, this is the secret used to perform an
Access-Request with the username (set by B<login> above) and passwd (set by
B<passwd> above).
Default: empty string
B<scheduler => I<scheduler_name>
Scheduler to be used by LVS for loadbalancing.
For an information on the available sehedulers please see
the ipvsadm(8) man page.
Default: "wrr"
B<persistent => I<n>
Number of seconds for persistent client connections.
B<netmask => I<w.x.y.z>
Netmask to be used for granularity of persistent client connections.
B<protocol = tcp> | B<udp> | B<fwm>
Protocol to be used. If the virtual is specified as an IP address and port
then it must be one of tcp or udp. If a firewall
mark then the protocol must be fwm.
Default:
=over 4
=item * Virtual is an IP address and port, and the port is not 53: tcp
=item * Virtual is an IP address and port, and the port is 53: udp
=item * Virtual is a firewall mark: fwm
=back
B<monitorfile = ">I</path/to/monitorfile>B<">
File to continuously log the real service checks to for this virtual
service. This is useful for monitoring when and why real services were down
or for statistics.
The log format is:
[timestamp|pid|real_service_id|status|message]
Default: no separate logging of service checks.
=head1 IPv6
Directives for IPv6 are virtual6, real6, fallback6.
IPv6 addresses specified for virtual6, real6, fallback6 and a file
of maintenance directory should be enclosed by
brackets ([2001:db8::abcd]:80).
Following checktype and service are supported.
B<checktype: >B<connect> | B<external> | B<external-perl> | B<negotiate> | B<off> | B<on> | B<checktimeout>I<N>
B<service: >B<dns> | B<nntp> | B<none> | B<simpletcp> | B<sip>
=head1 FILES
B</usr/etc/ha.d/ldirectord.cf>
B</var/log/ldirectord.log>
B</var/run/ldirectord.>I<configuration>B<.pid>
B</etc/services>
=head1 SEE ALSO
L<ipvsadm>, L<heartbeat>
Ldirectord Web Page: http://www.vergenet.net/linux/ldirectord/
=head1 AUTHORS
Horms <[email protected]>
Jacob Rief <[email protected]>
=cut
use strict;
# Set defaults for configuration variables in the "set_defaults" function
use vars qw(
$VERSION_STR
$AUTOCHECK
$CHECKINTERVAL
$LDIRECTORD
$LDIRLOG
$NEGOTIATETIMEOUT
$DEFAULT_NEGOTIATETIMEOUT
$RUNPID
$CHECKTIMEOUT
$DEFAULT_CHECKTIMEOUT
$CHECKCOUNT
$FAILURECOUNT
$QUIESCENT
$FORKING
$EMAILALERT
$EMAILALERTFREQ
$EMAILALERTSTATUS
$EMAILALERTFROM
$SMTP
$CLEANSTOP
$MAINTDIR
$CONTROLPOINT
$CALLBACK
$CFGNAME
$CMD
$CONFIG
$DEBUG
$FALLBACK
$FALLBACK6
$FALLBACKCOMMAND
$SUPERVISED
$PY_NSUPDATE
$checksum
$DAEMON_STATUS
$DAEMON_STATUS_STARTING
$DAEMON_STATUS_RUNNING
$DAEMON_STATUS_STOPPING
$DAEMON_STATUS_RELOADING
$DAEMON_STATUS_ALL
$DAEMON_TERM
$DAEMON_HUP
$DAEMON_CHLD
$opt_d
$opt_h
$stattime
%LD_INSTANCE
@OLDVIRTUAL
@REAL
@VIRTUAL
$HOSTNAME
%EMAILSTATUS
%FORK_CHILDREN
$SERVICE_UP
$SERVICE_DOWN
%check_external_perl__funcs
$CRLF
);
$VERSION_STR = "Linux Director v1.186-ha";
$DAEMON_STATUS_STARTING = 0x1;
$DAEMON_STATUS_RUNNING = 0x2;
$DAEMON_STATUS_STOPPING = 0x4;
$DAEMON_STATUS_RELOADING = 0x8;
$DAEMON_STATUS_ALL = $DAEMON_STATUS_STARTING |
$DAEMON_STATUS_RUNNING |
$DAEMON_STATUS_STOPPING |
$DAEMON_STATUS_RELOADING;
$SERVICE_UP = 0;
$SERVICE_DOWN =1;
# default values
$DAEMON_TERM = undef;
$DAEMON_HUP = undef;
$LDIRECTORD = ld_find_cmd("nsdirectord", 1);
if (! defined $LDIRECTORD) {
$LDIRECTORD = "/usr/sbin/nsdirectord";
}
$RUNPID = "/var/run/nsdirectord";
$CRLF = "\x0d\x0a";
# Set global configuration default values:
set_defaults();
use Getopt::Long;
use Pod::Usage;
#use English;
#use Time::HiRes qw( gettimeofday tv_interval );
use Socket;
use Socket6;
use Sys::Hostname;
use POSIX qw(setsid :sys_wait_h);
use Sys::Syslog qw(:DEFAULT setlogsock);
BEGIN
{
# wrap exit() to preserve replacability
*CORE::GLOBAL::exit = sub { CORE::exit(@_ ? shift : 0); };
}
# command line options
my @OLD_ARGV = @ARGV;
my $opt_d = '';
my $opt_h = '';
my $opt_v = '';
Getopt::Long::Configure ("bundling", "no_auto_abbrev", "require_order");
GetOptions("debug|d" => \$opt_d,
"help|h|?" => \$opt_h,
"version|v" => \$opt_v) or usage();
# main code
$DEBUG = $opt_d ? 3 : 0;
if ($opt_h) {
exec_wrapper("/usr/bin/perldoc -U $LDIRECTORD");
&ld_exit(127, "Exec failed");
}
if ($opt_v) {
print("$VERSION_STR\n" .
"1999-2006 Jacob Rief, Horms and others\n" .
"<http://www.vergenet.net/linux/ldirectord/>\n".
"\n" .
"nsdirectord comes with ABSOLUTELY NO WARRANTY.\n" .
"This is free software, and you are welcome to redistribute it\n".
"under certain conditions. " .
"See the GNU General Public Licence for details.\n");
&ld_exit(0, "");
}
if ($DEBUG>0 and -f "./py-nsupdate") {
$PY_NSUPDATE="./py-nsupdate";
} else {
if (-x "/bin/py-nsupdate") {
$PY_NSUPDATE="/bin/py-nsupdate";
} elsif (-x "/usr/bin/py-nsupdate") {
$PY_NSUPDATE="/usr/bin/py-nsupdate";
} else {
die "Can not find py-nsupdate";
}
}
# There is a memory leak in perl's socket code when
# the default IO layer is used. So use "perlio" unless
# something else has been explicitly set.
# http://archive.develooper.com/[email protected]/msg85468.html
unless(defined($ENV{'PERLIO'})) {
$ENV{'PERLIO'} = "perlio";
exec_wrapper($0, @OLD_ARGV);
}
$DAEMON_STATUS = $DAEMON_STATUS_STARTING;
ld_init();
ld_setup();
ld_start();
ld_cmd_children("start", %LD_INSTANCE);
$DAEMON_STATUS = $DAEMON_STATUS_RUNNING;
ld_main();
&ld_rm_file("$RUNPID.$CFGNAME.pid");
&ld_exit(0, "Reached end of \"main\"");
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
};
# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
};
# Right trim function to remove trailing whitespace
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
};
sub parse_backets_str_parse_block_params($)
{
my $block_params = shift;
my $retval = {};
foreach my $l_param_str(split(/\s*\,\s*/, $block_params))
{
if ($l_param_str =~ /\:/)
{
my($l_pname, $l_pvalue) = split(/\s*\:\s*/, $l_param_str, 2);
$retval->{lc($l_pname)} = $l_pvalue;
}
else
{
my $l_pname = $l_param_str;
$retval->{lc($l_pname)} = 1;
};
};
return $retval;
};
sub parse_backets_str($)
{
my $line = shift;
my $retval = undef;
my $l_retval = {};
my $l_line = trim($line);
my $l_parse_error = 0;
while (length($l_line))
{
if($l_line =~ /(^([a-z]+)\s*\{([^\{\}]*)\})/)
{
my $l_block_name = uc($2);
my $l_block_params = parse_backets_str_parse_block_params($3);
$l_retval->{$l_block_name} = $l_block_params;
$l_line = ltrim(substr($l_line, length($1)));
}
else
{
$l_parse_error = 1;
last;
};
};
if(!$l_parse_error)
{
$retval = $l_retval;
};
return $retval;
};
# functions
sub ld_init
{
# install signal handlers (this covers TERM)
#require Net::LDAP;
$SIG{'INT'} = \&ld_handler_term;
$SIG{'QUIT'} = \&ld_handler_term;
$SIG{'ILL'} = \&ld_handler_term;
$SIG{'ABRT'} = \&ld_handler_term;
$SIG{'FPE'} = \&ld_handler_term;
$SIG{'SEGV'} = \&ld_handler_term;
$SIG{'TERM'} = \&ld_handler_term;
$SIG{'BUS'} = \&ld_handler_term;
$SIG{'SYS'} = \&ld_handler_term;
$SIG{'XCPU'} = \&ld_handler_term;
$SIG{'XFSZ'} = \&ld_handler_term;
$SIG{'IOT'} = \&ld_handler_term;