I have created a patch for ldirectord.
The purpose of the patch is to solve this problem:
my set of http servers is tightly bound with a mysql database server;
the interactive website does not work if the DBMS is not available.
I have added a keyword master=IP:PORT to the definition of a virtual
service in the ldirectord.cf configuration file.
This makes this service dependent on another service, its 'master'.
If the master service happens to be down, also all real servers for
this virtual service will be down.
If Horms likes the idea, maybe he will integrate it into the official
ldirectord from Ultramonkey.
I have only implemented it for virtual services wich use
checktype=connect (the default)
Below is my example configuration file, and the patch.
Alois
# ldirectord.cf
# Global Directives
checktimeout=5
checkinterval=3
# Virtual Server for HTTP
virtual=199.49.62.59:80
fallback=127.0.0.1:80
real=10.1.1.1:80 masq 800
real=10.1.1.2:80 masq 1000
real=10.1.1.3:80 masq 1000
real=10.1.1.4:80 masq 1100
master=10.1.1.1:3306
service=http
request="index.html"
receive="Test Page"
scheduler=wlc
#persistent=600
protocol=tcp
# Virtual Server for mysql
virtual=199.49.62.59:3306
real=10.1.1.1:3306 masq
scheduler=rr
#persistent=600
protocol=tcp
---------------- end configuration file ------------
-------------- begin patch file ---------------
--- ldirectord.org Sun Apr 22 23:15:09 2001
+++ ldirectord Mon Jun 11 20:30:45 2001
@@ -230,6 +230,22 @@
then it must be one of tcp or udp and will default to tcp. If a firewall
mark then the protocol must be fwm, which is the default.
+B<master = >I<x.y.z.w:p>
+
+This virtual service depends on another service called the
+master service. If the master service is off, also all real servers
+for this virtual service will be turned off.
+
+The value is a pair of IP:PORT and must correspond to one
+of the real services configured in the current configuration.
+
+Example: the http services depend on the mysql database server,
+which is configured on 10.1.1.1:3306
+
+master = 10.1.1.1:3306 within the declaration of virtual http
+service has the effect that all http services will be set to off if
+the mysql server is off.
+
=head1 FILES
@@ -558,6 +574,7 @@
$vsrv{scheduler} = "wrr";
$vsrv{request} = "/";
$vsrv{receive} = "";
+ $vsrv{master} = "";
$vsrv{login} = "anonymous";
$vsrv{passwd} = "ldirectord\@$ENV{HOSTNAME}";
$vsrv{checktimeout} = 0;
@@ -611,6 +628,10 @@
} elsif ($rcmd =~
/^negotiatetimeout\s*=\s*(.*)/){
$1 =~ /(\d+)/ && $1 or
config_error($line, "invalid check timeout");
$vsrv{negotiatetimeout} = $1;
+ } elsif ($rcmd =~ /^master\s*=\s*(.*)/){
+ $1 =~
/(((\d+\.\d+\.\d+\.\d+):(\d+))|(\d+))/
+ or config_error($line, "invalid
address for master server");
+ $vsrv{master} = $1;
} elsif ($rcmd =~ /^checkport\s*=\s*(.*)/){
$1 =~ /(\d+)/ or config_error($line,
"invalid port");
( $1 > 0 && $1 < 65536 ) or
config_error($line, "checkport must be in range 1..65536");
@@ -1135,10 +1156,33 @@
return 0;
}
+# Alois
+sub check_master
+{
+ my ($v, $r) = @_;
+ if ($v->{master}) {
+ my $m = $v->{master};
+ # find the real server which is given here as IP:PORT
+ foreach my $vmy (@VIRTUAL) {
+ my $real = $$vmy{real};
+ foreach my $rmy (@$real) {
+ $rmy == $r and next;
+ if ("$$rmy{server}:$$rmy{port}" eq $m && $$rmy{status} != 1) {
+ &service_set($v, $r, "down");
+ &ld_debug(3, "Deactivating service $$r{server}:$$r{port}:
master $m status $$rmy{status}");
+ return 0;
+ }
+ }
+ }
+ }
+ return 1;
+}
sub check_connect
{
my ($v, $r) = @_;
+ # Alois
+ check_master($v, $r) != 0 or return 0;
my $port=(defined $$v{checkport}?$$v{checkport}:$$r{port});
eval {
|