Changes to how routes are handled when there is

only one VIP.
This commit is contained in:
YuruC3 2024-05-15 01:26:40 +02:00
parent 841e91b463
commit b69e0082af
6 changed files with 36 additions and 11 deletions

View File

@ -30,4 +30,11 @@ vrrp_instance <YOUR_MASTER_INSTANCE> {
track_npm
}
notify_master "/etc/keepalived/add_route.sh"
notify_backup "/etc/keepalived/rm_route.sh"
notify_fault "/etc/keepalived/rm_route.sh"
}

View File

@ -30,4 +30,11 @@ vrrp_instance NPM-V1 {
track_npm
}
notify_master "/etc/keepalived/add_route.sh"
notify_backup "/etc/keepalived/rm_route.sh"
notify_fault "/etc/keepalived/rm_route.sh"
}

View File

@ -30,4 +30,11 @@ vrrp_instance NPM-V1 {
track_npm
}
notify_master "/etc/keepalived/add_route.sh"
notify_backup "/etc/keepalived/rm_route.sh"
notify_fault "/etc/keepalived/rm_route.sh"
}

2
add_route.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
ip route add <dest_net> via <gateway> dev <port>

View File

@ -16,13 +16,13 @@ container_name=$1
check_container_health() {
# Get the health status of the container
health_status=$(sudo docker inspect --format='{{.State.Health.Status}}' "$1")
health_status=$(docker inspect --format='{{.State.Health.Status}}' "$1")
# Check the health status and return 0 if healthy, 1 if unhealthy
if [[ "$health_status" = "healthy" > /dev/null 2>&1 ]]; then
if [[ "$health_status" = "healthy" ]]; then
return 0
elif [[ "$health_status" = "starting" > /dev/null 2>&1 ]]; then
elif [[ "$health_status" = "starting" ]]; then
echo "Container in starting state"
sleep 15
@ -35,20 +35,20 @@ check_container_health() {
}
# Debugging output
echo "Checking container: $container_name"
#echo "Checking container: $container_name"
state_restarting=$(sudo docker inspect --format="{{.State.Restarting}}" "$container_name")
state_running=$(sudo docker inspect --format="{{.State.Running}}" "$container_name" 2> /dev/null)
state_restarting=$(docker inspect --format="{{.State.Restarting}}" "$container_name")
state_running=$(docker inspect --format="{{.State.Running}}" "$container_name")
# Debugging output
echo "Restarting: $state_restarting"
echo "Running: $state_running"
#echo "Restarting: $state_restarting"
#echo "Running: $state_running"
if [ "$state_restarting" = "false" ] && [ "$state_running" = "true" > /dev/null 2>&1 ]; then
echo "Container is in the expected state. Exiting with status 0."
if [ "$state_restarting" = "false" ] && [ "$state_running" = "true" ]; then
#echo "Container is in the expected state. Exiting with status 0."
exit 0
else
echo "Container is not in the expected state. Exiting with status 1."
#echo "Container is not in the expected state. Exiting with status 1."
exit 1
fi

2
rm_route.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
ip route del <dest_net> via <gateway> dev <port>