summaryrefslogtreecommitdiff
path: root/scripts/keepalived
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@vyatta.com>2008-05-09 18:39:56 -0700
committerStig Thormodsrud <stig@vyatta.com>2008-05-09 18:39:56 -0700
commit6c47fa4846c453964709c02891adb4e582e4cf93 (patch)
tree7631d6fbf8db39d4204da3958ba115b64d4b4ff8 /scripts/keepalived
parent9bc06ac99e68468f05ecd5aa2be8579f4d5112a1 (diff)
downloadvyatta-cfg-quagga-6c47fa4846c453964709c02891adb4e582e4cf93.tar.gz
vyatta-cfg-quagga-6c47fa4846c453964709c02891adb4e582e4cf93.zip
Set initial vrrp state based on existing state if available.
Diffstat (limited to 'scripts/keepalived')
-rwxr-xr-xscripts/keepalived/vyatta-keepalived.pl37
1 files changed, 30 insertions, 7 deletions
diff --git a/scripts/keepalived/vyatta-keepalived.pl b/scripts/keepalived/vyatta-keepalived.pl
index c10a1ca7..7389534b 100755
--- a/scripts/keepalived/vyatta-keepalived.pl
+++ b/scripts/keepalived/vyatta-keepalived.pl
@@ -36,6 +36,33 @@ my $conf_file = VyattaKeepalived::get_conf_file();
my %HoA_sync_groups;
+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);
+ 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;
+}
sub keepalived_get_values {
my ($intf, $path) = @_;
@@ -90,7 +117,7 @@ sub keepalived_get_values {
}
}
- $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts");
+ $config->setLevel("$path vrrp vrrp-group $group run-transition-scripts");
my $run_backup_script = $config->returnValue("backup");
if(!defined $run_backup_script){
$run_backup_script = "null";
@@ -104,13 +131,9 @@ sub keepalived_get_values {
$run_master_script = "null";
}
-
$output .= "vrrp_instance $vrrp_instance \{\n";
- if ($preempt eq "false") {
- $output .= "\tstate BACKUP\n";
- } else {
- $output .= "\tstate MASTER\n";
- }
+ my $init_state = vrrp_get_init_state($intf, $group, $vips[0], $preempt);
+ $output .= "\tstate $init_state\n";
$output .= "\tinterface $intf\n";
$output .= "\tvirtual_router_id $group\n";
$output .= "\tpriority $priority\n";