Add functionality for keepalived check script

This will add a hook to allow keepalived to run a check script if the
script variable is defined.
pull/108/head
Dan Kelleher 7 years ago
parent a8baa826d2
commit 838a708e8f

@ -53,6 +53,12 @@ get_vrouter_password() {
echo $password echo $password
} }
get_check_script() {
script="$VROUTER_KEEPALIVED_CHECK_SCRIPT"
echo $script
}
get_iface_var() { get_iface_var() {
var_name="$1_$2" var_name="$1_$2"
var=$(eval "echo \"\${$var_name}\"") var=$(eval "echo \"\${$var_name}\"")
@ -81,6 +87,22 @@ EOT
EOT EOT
} }
gen_check_script() {
script="$(get_check_script)"
if [ -n "$script" ]; then
cat <<EOT
vrrp_script chk_script {
script "$script"
interval 2
fall 2
rise 2
}
EOT
fi
}
gen_auth() { gen_auth() {
password=$(get_vrouter_password) password=$(get_vrouter_password)
@ -94,6 +116,26 @@ EOT
fi fi
} }
gen_track() {
script="$(get_check_script)"
if [ -n "$script" ]; then
cat <<EOT
track_script {
chk_script
}
EOT
fi
}
gen_preempt() {
script="$(get_check_script)"
if [ -z "$script" ]; then
echo nopreempt
fi
}
gen_instances() { gen_instances() {
for interface in $(get_context_interfaces); do for interface in $(get_context_interfaces); do
vrouter_ip=$(get_iface_var $interface VROUTER_IP) vrouter_ip=$(get_iface_var $interface VROUTER_IP)
@ -111,7 +153,8 @@ vrrp_instance $interface {
$vrouter_ip $vrouter_ip
} }
$(gen_auth) $(gen_auth)
nopreempt $(gen_track)
$(gen_preempt)
} }
EOT EOT
@ -133,6 +176,7 @@ fi
( (
gen_group gen_group
gen_check_script
gen_instances gen_instances
) > /etc/keepalived/keepalived.conf ) > /etc/keepalived/keepalived.conf

Loading…
Cancel
Save