On Thu, Sep 04, 2008 at 05:55:39PM +0200, Julius Volz wrote:
> Hi,
>
> Just posting this patch in case it's useful for someone. Not sure if it
> makes sense to include it (see below why). It basically adds this option
> to ldirectord:
Hi Julius,
I don't really see much harm in adding it as it is an option.
It can always be enhanced later, if there is a need.
Applied :-)
> ===================
> fallbackcommand = "path to script"
>
> If this directive is defined, the supplied script is executed whenever
> all real servers for a virtual sreve 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".
> ===================
>
> The current ldirectord does a fallback on startup and then only stops
> the fallback once the first real server is checked and up. Because this
> new option is tied to the existing code, the fallback script is also
> started and stopped once at the startup of ldirectord, which might be
> annoying for some users. That's why I'm not sure if there is general
> interest in including it like this. I didn't dig deeper into the
> ldirectord code to prevent this startup behavior from happening because
> we actually want this behavior.
>
> Julius
>
> diff -r ae210ba284e4 ldirectord/ldirectord.in
> --- a/ldirectord/ldirectord.in Mon Sep 01 14:20:57 2008 +0200
> +++ b/ldirectord/ldirectord.in Wed Sep 03 17:09:03 2008 +0200
> @@ -181,6 +181,15 @@ the server onto which a webservice is re
> 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.
>
> @@ -618,6 +627,7 @@ use vars qw(
> $CONFIG
> $DEBUG
> $FALLBACK
> + $FALLBACKCOMMAND
> $SUPERVISED
> $IPVSADM
> $checksum
> @@ -1303,6 +1313,9 @@ sub read_config
> $vsrv{fallback} =
> parse_fallback($line, $1,
> \%vsrv);
> + } elsif ($rcmd =~
> /^fallbackcommand\s*=\s*(.*)/) {
> + $1 =~ /(.+)/ or &config_error($line,
> "invalid fallback command");
> + $vsrv{fallbackcommand} = $1;
> } elsif ($rcmd =~ /^quiescent\s*=\s*(.*)/) {
> ($1 eq "yes" || $1 eq "no")
> or &config_error($line,
> "quiescent must be 'yes' or 'no'");
> @@ -1381,6 +1394,9 @@ sub read_config
> &_ld_read_config_fallback_resolve($line, "tcp",
> $tcp);
> &_ld_read_config_fallback_resolve($line, "udp", $udp);
> $FALLBACK = { "tcp" => $tcp, "udp" => $udp };
> + } elsif ($linedata =~ /^fallbackcommand\s*=\s*(.*)/) {
> + $1 =~ /(.+)/ or &config_error($line, "invalid fallback
> command");
> + $FALLBACKCOMMAND = $1;
> } elsif ($linedata =~ /^autoreload\s*=\s*(.*)/) {
> ($1 eq "yes" || $1 eq "no")
> or &config_error($line,
> @@ -3652,14 +3668,16 @@ sub fallback_on
>
> my $fallback=&fallback_find($v);
>
> - if (! defined($fallback) or (! _status_up($v, $fallback, "fallback")
> - and ! defined($force))) {
> - return;
> - }
> -
> - &_restore_service($v, $fallback->{server} . ":" . $fallback->{port},
> - get_forward_flag($fallback->{forward}),
> - "1", "fallback");
> + if (defined($fallback) and (_status_up($v, $fallback, "fallback")
> + or defined($force))) {
> + &_restore_service($v, $fallback->{server} . ":" .
> $fallback->{port},
> + get_forward_flag($fallback->{forward}),
> + "1", "fallback");
> + }
> +
> + if (!defined ($v->{real_status})) {
> + &do_fallback_command($v, "start");
> + }
> }
>
>
> @@ -3675,14 +3693,16 @@ sub fallback_off
>
> my $fallback=&fallback_find($v);
>
> - if (! defined($fallback) or (! _status_down($v, $fallback, "fallback")
> - and ! defined($force))) {
> - return;
> - }
> -
> - &_remove_service($v, $fallback->{server} . ":" . $fallback->{port},
> - get_forward_flag($fallback->{forward}),
> - "fallback");
> + if (defined($fallback) and (_status_down($v, $fallback, "fallback")
> + or defined($force))) {
> + &_remove_service($v, $fallback->{server} . ":" .
> $fallback->{port},
> + get_forward_flag($fallback->{forward}),
> + "fallback");
> + }
> +
> + if (defined ($v->{real_status})) {
> + &do_fallback_command($v, "stop");
> + }
> }
>
>
> @@ -3716,6 +3736,27 @@ sub fallback_find
> return \%anon_fallback;
> }
>
> +
> +# fallback_command
> +# Execute the fallback command with the given status if it wasn't executed
> +# with this status already for the supplied virtual service.
> +
> +sub do_fallback_command()
> +{
> + my ($v, $status) = (@_);
> +
> + if (defined $v->{fallbackcommand_status} and
> $v->{fallbackcommand_status} eq $status) {
> + return;
> + }
> +
> + $v->{fallbackcommand_status} = $status;
> +
> + if (defined($v->{fallbackcommand})) {
> + &system_wrapper($v->{fallbackcommand} . " " . $status);
> + } elsif (defined($FALLBACKCOMMAND)) {
> + &system_wrapper($FALLBACKCOMMAND . " " . $status);
> + }
> +}
>
> # Used during stop, start and reload to remove stale real servers from LVS
> sub purge_untracked_service
--
Simon Horman
VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
H: www.vergenet.net/~horms/ W: www.valinux.co.jp/en
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/