diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2008-06-06 13:47:36 -0700 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2008-06-06 13:47:36 -0700 |
commit | f498c7b59b8a4784c14b3affcb2d796ab3814138 (patch) | |
tree | 4a870cc9ac25ed5a1b573d27616f52a8ba996e3a /scripts/keepalived/VyattaKeepalived.pm | |
parent | fff0ed76b20569d50f8e2aca1500602ab6686b21 (diff) | |
download | vyatta-cfg-quagga-f498c7b59b8a4784c14b3affcb2d796ab3814138.tar.gz vyatta-cfg-quagga-f498c7b59b8a4784c14b3affcb2d796ab3814138.zip |
Fix 787: Add a command to force vrrp state transition to backup
Diffstat (limited to 'scripts/keepalived/VyattaKeepalived.pm')
-rwxr-xr-x | scripts/keepalived/VyattaKeepalived.pm | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/scripts/keepalived/VyattaKeepalived.pm b/scripts/keepalived/VyattaKeepalived.pm index c9abe49e..6507d8f7 100755 --- a/scripts/keepalived/VyattaKeepalived.pm +++ b/scripts/keepalived/VyattaKeepalived.pm @@ -48,7 +48,7 @@ sub vrrp_log { sub is_running { if (-f $keepalived_pid) { my $pid = `cat $keepalived_pid`; - chomp $pid; + $pid =~ s/\s+$//; # chomp doesn't remove nl my $ps = `ps -p $pid -o comm=`; if (defined($ps) && $ps ne "") { @@ -70,6 +70,7 @@ sub start_daemon { sub stop_daemon { if (is_running()) { my $pid = `cat $keepalived_pid`; + $pid =~ s/\s+$//; # chomp doesn't remove nl system("kill $pid"); vrrp_log("stop_daemon"); } else { @@ -82,7 +83,7 @@ sub restart_daemon { if (VyattaKeepalived::is_running()) { my $pid = `cat $keepalived_pid`; - chomp $pid; + $pid =~ s/\s+$//; # chomp doesn't remove nl system("kill -1 $pid"); vrrp_log("restart_deamon"); } else { @@ -216,6 +217,7 @@ sub snoop_for_master { sub vrrp_state_parse { my ($file) = @_; + $file =~ s/\s+$//; # chomp doesn't remove nl if ( -f $file) { my $line = `cat $file`; chomp $line; @@ -226,4 +228,34 @@ sub vrrp_state_parse { } } +sub vrrp_get_init_state { + my ($intf, $group, $vips, $preempt) = @_; + + my $init_state; + if (VyattaKeepalived::is_running()) { + my @state_files = VyattaKeepalived::get_state_files($intf, $group); + chomp @state_files; + if (scalar(@state_files) > 0) { + my ($start_time, $f_intf, $f_group, $state, $ltime) = + VyattaKeepalived::vrrp_state_parse($state_files[0]); + if ($state eq "master") { + $init_state = 'MASTER'; + } else { + $init_state = 'BACKUP'; + } + return $init_state; + } + # fall through to logic below + } + + if ($preempt eq "false") { + $init_state = 'BACKUP'; + } else { + $init_state = 'MASTER'; + } + + return $init_state; +} + +1; #end of file |