Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F7454259
migrate_vip.sh
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
SrividyaA
Jan 10 2025, 2:57 PM
2025-01-10 14:57:05 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
migrate_vip.sh
View Options
#!/bin/vbash
# Define variables
PING_TARGET
=
"1.1.1.1"
PING_COUNT
=
3
VRRP_GROUP
=
"vrrp0"
LOW_PRIORITY
=
50
NORMAL_PRIORITY
=
200
LOG_FILE
=
"/var/log/vrrp_migrate.log"
# Logging function
log
()
{
echo
"
$(
date
)
:
$1
"
|
tee
-a
$LOG_FILE
}
# Load VyOS environment
source
/opt/vyatta/etc/functions/script-template
# Get the current VRRP priority
CURRENT_PRIORITY
=
$(
run
show
configuration
commands
|
grep
"set high-availability vrrp group
$VRRP_GROUP
priority"
|
awk
'{print $7}'
)
# Log current state
log
"Starting VRRP monitoring script. Current priority:
$CURRENT_PRIORITY
."
# Check connectivity to the target
if
!
ping
-c
$PING_COUNT
$PING_TARGET
>
/dev/null
;
then
log
"Ping to
$PING_TARGET
failed."
if
[
"
$CURRENT_PRIORITY
"
!
=
"
$LOW_PRIORITY
"
]
;
then
log
"Reducing VRRP priority to
$LOW_PRIORITY
."
configure
set
high-availability
vrrp
group
$VRRP_GROUP
priority
$LOW_PRIORITY
commit
save
log
"VRRP priority updated to
$LOW_PRIORITY
."
else
log
"Priority already set to
$LOW_PRIORITY
. No changes needed."
fi
else
log
"Ping to
$PING_TARGET
succeeded."
if
[
"
$CURRENT_PRIORITY
"
!
=
"
$NORMAL_PRIORITY
"
]
;
then
log
"Restoring VRRP priority to
$NORMAL_PRIORITY
."
configure
set
high-availability
vrrp
group
$VRRP_GROUP
priority
$NORMAL_PRIORITY
commit
save
log
"VRRP priority updated to
$NORMAL_PRIORITY
."
else
log
"Priority already set to
$NORMAL_PRIORITY
. No changes needed."
fi
fi
log
"VRRP monitoring script completed."
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1081724
Default Alt Text
migrate_vip.sh (1 KB)
Attached To
Mode
T7040: Losing configuration after a power failure/reset
Attached
Detach File
Event Timeline
Log In to Comment