Skip to main content

Keepalived

keepalived.conf
global_defs {
enable_script_security
script_user root
}

vrrp_instance VI_1 {
state MASTER
interface eno1
virtual_router_id 42
priority 64
advert_int 1
authentication {
auth_type PASS
auth_pass sxdsC66K
}
virtual_ipaddress {
10.10.10.10/24
}
notify /opt/slg/broadcastsuite/samples/keepalived_notify.sh
}

On the secondary server, the priority value must be lower than the primary server's value. The higher the value, the higher the priority.

keepalived_notify.sh
#!/bin/bash

ENDSTATE=$3
NAME=$2
TYPE=$1

NODESTATE=2

case $ENDSTATE in
"BACKUP") # Transition to BACKUP state
echo "Setting Broadcast Suite role to SECONDARY"
NODESTATE=2
;;
"FAULT") # Transition to FAULT state
echo "Setting Broadcast Suite role to SECONDARY"
NODESTATE=2
;;
"MASTER") # Transition to MASTER state
echo "Setting Broadcast Suite role to PRIMARY"
NODESTATE=1
;;
*) echo "Unknown state ${ENDSTATE} for VRRP ${TYPE} ${NAME}"
exit 1
;;
esac

curl -X POST -H "Content-Type: application/json" \
-d '{}' \
http://127.0.0.1:8085/api/v1/system/NodeState?NodeState=$NODESTATE

exit 0;
SELinux

If your server has SELinux enabled, the script execution must be permitted with the following command: chcon -t keepalived_unconfined_script_exec_t /opt/slg/broadcastsuite/samples/keepalived_notify.sh