LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: ldirectord patch

To: "LinuxVirtualServer.org users mailing list." <lvs-users@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: ldirectord patch
From: "jarol1@xxxxxxxxx" <J.Libak@xxxxxxxxxx>
Date: Fri, 12 Jan 2007 15:14:38 +0100
Graeme Fowler wrote:
On 12/01/2007 09:59, Jaroslav Libák wrote:
Last time attachment wasnt sent for some reason.

The list MLM strips attachments. Best to either put it in the body of the message or, if it's a biggun, put it somewhere accessible and send the URL.

Graeme
_______________________________________________
LinuxVirtualServer.org mailing list - lvs-users@xxxxxxxxxxxxxxxxxxxxxx
Send requests to lvs-users-request@xxxxxxxxxxxxxxxxxxxxxx
or go to http://www.in-addr.de/mailman/listinfo/lvs-users

Here it is:

diff -ru original/ldirectord patchedldirector/ldirectord
--- original/ldirectord    2006-11-03 01:24:56.000000000 +0100
+++ patchedldirector/ldirectord    2007-01-12 10:35:59.000000000 +0100
@@ -248,7 +248,7 @@
also appear inside a virtual section, in which case the global setting is
overridden.

-B<checktype = >I<negotiate>|I<connect>|I<N>|I<ping>|I<off>|I<on>
+B<checktype = >I<negotiate>|I<connect>|I<N>|I<ping>|I<off>|I<on>|I<external>

Type of check to perform. Negotiate sends a request and matches a receive
string. Connect only attemts to make a TCP/IP connection, thus the
@@ -271,6 +271,14 @@
B<imap>, <B<imaps>, B<ldap>, B<https>, B<mysql>, B<pgsql> or B<sip> respectivly.
Otherwise the default service is B<none>.

+B<externalpath = ">I<path to script>B<">
+
+This setting is taken into account if checktype is external - by external
+script. Enter path of the script into double quotes. Script should return
+0 if everything is ok, or something else if it isn't. 4 parameters are passed
+to the script - virtual server ip/firewall mark, virtual server port,
+real server ip, real server port
+
B<checkport = >I<n>

Number of port to monitor. Sometimes check port differs from service port.
@@ -816,6 +824,7 @@
            }
            $vsrv{real} = \@rsrv;
            $vsrv{scheduler} = "wrr";
+            $vsrv{externalpath} = "/bin/true";
            $vsrv{request} = "/";
            $vsrv{receive} = "";
            $vsrv{login} = "";
@@ -856,11 +865,14 @@
                    if ($1 =~ /(\d+)/ && $1>=0) {
                        $vsrv{num_connects} = $1;
                        $vsrv{checktype} = "combined";
- } elsif ( $1 =~ /(\w+)/ && ($1 eq "connect" || $1 eq "negotiate" || $1 eq "ping" || $1 eq "off" || $1 eq "on") ) { + } elsif ( $1 =~ /(\w+)/ && ($1 eq "connect" || $1 eq "negotiate" || $1 eq "ping" || $1 eq "off" || $1 eq "on" || $1 eq "external") ) {
                        $vsrv{checktype} = $1;
                    } else {
- &config_error($line, "checktype must be connect, negotiate, ping, off, on or a positive number"); + &config_error($line, "checktype must be connect, negotiate, ping, off, on, external or a positive number");
                    }
+                } elsif ($rcmd =~ /^externalpath\s*=\s*(.*)/){
+ $1 =~ /(.+)/ or &config_error($line, "invalid external script");
+                                        $vsrv{externalpath} = $1;
                } elsif ($rcmd =~ /^checktimeout\s*=\s*(.*)/){
$1 =~ /(\d+)/ && $1 or &config_error($line, "invalid check timeout");
                                        $vsrv{checktimeout} = $1;
@@ -1836,6 +1848,9 @@
                } elsif ($$v{checktype} eq "ping") {
&ld_debug(2, "Checking ping: real server=$real_id (virtual=$virtual_id)");
                    check_ping($v, $r);
+                } elsif ($$v{checktype} eq "external") {
+ &ld_debug(2, "Checking external: real server=$real_id (virtual=$virtual_id)");
+                    check_external($v, $r);
                } elsif ($$v{checktype} eq "off") {
&ld_debug(2, "Checking off: No real or fallback servers to be added\n");
                } elsif ($$v{checktype} eq "on") {
@@ -2256,6 +2271,37 @@
    }
}

+sub check_external
+{
+    my ($v, $r) = @_;
+    my $result;
+    my $v_server;
+
+    eval {
+        local $SIG{'__DIE__'} = "DEFAULT";
+        local $SIG{'ALRM'} = sub { die "Timeout Alarm" };
+        &ld_debug(4, "Timeout is $$v{checktimeout}");
+        alarm $$v{checktimeout};
+        if (defined $$v{server}) {
+            $v_server = $$v{server};
+        } else {
+            $v_server = $$v{fwm};
+        }
+ $result = system("$$v{externalpath} $v_server $$v{port} $$r{server} $$r{port}");
+        alarm 0;
+        $result >>= 8;
+    };
+    if ($@ or $result != 0) {
+        &service_set($v, $r, "down");
+ &ld_debug(3, "Deactivated service $$r{server}:$$r{port}: $@ after calling $$v{externalpath} with result $result");
+        return 0;
+    } else {
+        &service_set($v, $r, "up");
+        &ld_debug(3, "Activated service $$r{server}:$$r{port}");
+        return 1;
+    }
+}
+

sub check_sip
{


<Prev in Thread] Current Thread [Next in Thread>