Score:0

Keepalived: Transitioning to backup node not happening when check script on master server finds service is down for an applicaiton

eg flag

I am trying to configure keepalived in such a way that if any application or service running on master node fails, keepalived should consider it as fault and backup node should act as master and take over the floating IP from master node.

I have written a script to check if service X on master server goes down, then it should transition to backup node.

My keepalived conf are:

global_defs {
enable_script_security
}
vrrp_script keepalived_check {
script "/root/new/check.sh"
interval 1
timeout 1
rise 2
fall 2
weight 0 reverse
}
vrrp_instance V1_11 {
state MASTER
interface ens3
virtual_router_id 51
priority 101
advert_int 1
unicast_src_ip 192.168.10.129
unicast_peer {
    192.168.10.130
}
authentication {
    auth_type PASS
    auth_pass 1122
}
virtual_ipaddress {
    192.168.10.231/24
}
track_script {
    keepalived_check
}
}

The Script that checks the service status:

#!/bin/bash
var="$(systemctl is-active myservice.service)"

if [ $var == "active" ]
then
    echo 0
else
    echo 5
fi

I manually stopped the "myservice" using

systemctl stop myservice.service

The output for script is "5" as expected. But with above mentioned configurations, master node remains as primary node and it doesn't shift ownership to backup node. Is there any particular config that I have missed then kindly help me find that?

Score:0
br flag

Ciao just because I had the same issue, let me share my workaround. Do not ask me why but I have been forced to restart keepalived process after the script fails because the monitored process is marked as DOWN.

Moreover, in my situation (Ubuntu 20.04) the only exit codes that keepalived processes are 0 and 1.

So without changing anything to your keepalived.conf you can just adapt the script to the following:

#!/bin/sh
var=$(systemctl is-active apache2)
if [ "$var" = "active" ]
then
  exit 0
else
  #workaround
  systemctl restart keepalived
  exit 1
fi

it should work also for you! Good luck.

PS for any other future reader, please make sure you can execute the script by keepalived_script user

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.