Last active
February 4, 2024 22:22
-
-
Save MrLenin/43ca144b45d37b25334b86fce5ab0a4a to your computer and use it in GitHub Desktop.
Vyos VRRP Helper Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
source /opt/vyatta/etc/functions/script-template | |
if [ "$(id -g -n)" != 'vyattacfg' ] ; then | |
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" | |
fi | |
VRRP_NEW_STATE=BACKUP | |
lock="/var/lock/vrrp-state" | |
exec {fd}>$lock | |
flock --timeout 10 "$fd" || exit | |
echo "$VRRP_NEW_STATE" > /config/user-data/vrrp-new.state | |
flock -u "$fd" | |
/config/scripts/vrrp-hook-queue.script & | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
source /opt/vyatta/etc/functions/script-template | |
if [ "$(id -g -n)" != 'vyattacfg' ] ; then | |
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" | |
fi | |
VRRP_NEW_STATE=FAULT | |
lock="/var/lock/vrrp-state" | |
exec {fd}>$lock | |
flock --timeout 10 "$fd" || exit | |
echo "$VRRP_NEW_STATE" > /config/user-data/vrrp-new.state | |
flock -u "$fd" | |
/config/scripts/vrrp-hook-queue.script & | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
if [ "$(id -g -n)" != 'vyattacfg' ] ; then | |
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" | |
fi | |
mySelf=$(basename $0) | |
lock="/var/lock/${mySelf}" | |
exec {fd}>$lock | |
flock --timeout 5 "$fd" || exit | |
source /opt/vyatta/etc/functions/script-template | |
VRRP_STATES="((MASTER)|(BACKUP)|(FAULT)|(UNKNOWN))" | |
function read_newest_state () { | |
local lock="/var/lock/vrrp-state" | |
exec {read_fd}>$lock | |
flock -s "$read_fd" | |
VRRP_NEWEST_STATE=$(</config/user-data/vrrp-new.state) | |
flock -u "$read_fd" | |
} | |
function read_current_state () { | |
local vrrp_status=$(sudo cat /var/run/vyatta-conntrackd-failover-state) | |
[[ $vrrp_status =~ $VRRP_STATES ]] | |
VRRP_CURRENT_STATE=${BASH_REMATCH[1]} | |
if [[ !($VRRP_CURRENT_STATE =~ $VRRP_STATES) ]] | |
then | |
exit 1 | |
fi | |
} | |
function do_master () { | |
# Stuff | |
} | |
function do_backup () { | |
# Stuff | |
} | |
read_newest_state | |
read_current_state | |
until [[ $VRRP_CURRENT_STATE = $VRRP_NEWEST_STATE ]] | |
do | |
case $VRRP_NEWEST_STATE in | |
BACKUP | \ | |
FAULT | \ | |
STOP) | |
do_backup | |
;; | |
MASTER) | |
do_master | |
;; | |
esac | |
read_current_state | |
if [[ $VRRP_CURRENT_STATE = "UNKNOWN" && $VRRP_NEWEST_STATE = "STOP" ]]; then | |
VRRP_CURRENT_STATE=STOP | |
fi | |
read_newest_state | |
done | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
source /opt/vyatta/etc/functions/script-template | |
if [ "$(id -g -n)" != 'vyattacfg' ] ; then | |
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" | |
fi | |
VRRP_NEW_STATE=MASTER | |
lock="/var/lock/vrrp-state" | |
exec {fd}>$lock | |
flock --timeout 10 "$fd" || exit | |
echo "$VRRP_NEW_STATE" > /config/user-data/vrrp-new.state | |
flock -u "$fd" | |
/config/scripts/vrrp-hook-queue.script & | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
source /opt/vyatta/etc/functions/script-template | |
if [ "$(id -g -n)" != 'vyattacfg' ] ; then | |
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@" | |
fi | |
VRRP_NEW_STATE=STOP | |
lock="/var/lock/vrrp-state" | |
exec {fd}>$lock | |
flock --timeout 10 "$fd" || exit | |
echo "$VRRP_NEW_STATE" > /config/user-data/vrrp-new.state | |
flock -u "$fd" | |
/config/scripts/vrrp-hook-queue.script & | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment