Perl script for fallover servers

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Sean Roe
Date:  
Subject: Perl script for fallover servers
Hi all,

I am having some problems setting up a fallover server. I am using the mon
program to do it.

But the lvs.alert is having a problem. Here is the script:

================================================

#!/usr/bin/perl
#
# lvs.alert - Linux Virtual Server alert for mon
#
# It can be activated by mon to remove a real server when the
# service is down, or add the server when the service is up.
#
#
use Getopt::Std;
getopts ("s:g:h:t:l:P:V:R:W:F:U:");

$ipvsadm = "/sbin/ipvsadm";
$protocol = $opt_P;
$virtual_service = $opt_V;
$remote = $opt_R;
$state = $opt_U;



if ($state = "up") {
    $weight = $opt_W;
    if ($opt_F eq "nat") {
        $forwarding = "-m";
    } elsif ($opt_F eq "tun") {
        $forwarding = "-i";
    } else {
         $forwarding = "-g";
    }


    if ($protocol eq "tcp") {
        system("$ipvsadm -a -t $virtual_service -r $remote -w $weight
$forwarding");
    } else {
        system("$ipvsadm -a -u $virtual_service -r $remote -w $weight
$forwarding");
    }
} elsif ($state = "dn") {
    if ($protocol eq "tcp") {
        system("$ipvsadm -d -t $virtual_service -r $remote");
    } else {
        system("$ipvsadm -d -u $virtual_service -r $remote");
    }
};


=========================================================

Here is the config file that calls it:

watch sesserv01
    service ping
        interval 10s
        monitor fping.monitor
        period wd {Sun-Sat}
            alert mail.alert 
            upalert mail.alert 
            alert lvs.alert -P tcp -V 172.16.1.120:6969 -R 172.16.1.121 -W
1 -F nat -U dn
            alert lvs.alert -P tcp -V 172.16.1.120:6969 -R 172.16.1.122 -W
1 -F nat -U up
            upalert lvs.alert -P tcp -V 172.16.1.120:6969 -R 172.16.1.121 -W
1 -F nat -U up
            upalert lvs.alert -P tcp -V 172.16.1.120:6969 -R 172.16.1.122 -W
1 -F nat -U dn


Here is the issue:

It brings up one interface on the backup but wont down the primary interface
in ipvsadm. I think the issue is in the -U flag. The script doesn't seem
to be seeing it switch. Any ideas?

Thanks,
Sean