Yugabyte’s yba-ctl (the YBA Installer CLI) is a powerful tool for installing and managing YugabyteDB Anywhere (YBA), whether locally or in production. It handles installation, upgrades, service management (start, stop, status, etc.), backups, configuration, and more.
However, when it comes to high availability status, specifically whether a YBA instance is acting as the primary (leader) or standby (follower), yba-ctl currently offers no direct insight via its API.
The Limitation
Even though YBA supports an active-standby high availability (HA) model, yba-ctl doesn’t expose an API endpoint or command that indicates whether the current instance is the HA leader or a standby node. That means operations teams need a way to programmatically check the role of a YBA instance in the cluster..
Enter the Bash Script Solution
That’s where our custom bash script comes into play. By leveraging the YBA REST API endpoint
curl https:///api/v1/ha_leader
… you can determine the HA role programmatically and output a clear, human‑friendly message.
Here’s how it works:
• If the response indicates no HA config exists, the script prints:
No HA Config exists
• If the instance is the leader (primary), the script prints:
HA Leader (Primary)
• If the instance is a follower (standby), the script prints:
HA Follower (Standby)
Here’s the full script implementation that accepts a hostname or IP as a parameter (defaulting to 127.0.0.1 if none is provided):
#!/bin/bash
# Usage: ./check_ha_leader.sh [hostname_or_ip]
# Defaults to 127.0.0.1 if no argument is supplied
HOST="${1:-127.0.0.1}"
URL="https://${HOST}/api/v1/ha_leader"
RESPONSE=$(curl -sk "$URL")
if echo "$RESPONSE" | grep -q '"haleader":true'; then
echo "HA Leader (Primary)"
elif echo "$RESPONSE" | grep -q 'No HA Config exists'; then
echo "No HA Config exists"
elif echo "$RESPONSE" | grep -q 'HA follower'; then
echo "HA Follower (Standby)"
else
echo "Unexpected response: $RESPONSE"
fi
Save the script to a file called check_ha_leader.sh, and make it executable:
chmod +x check_ha_leader.sh
Example Run
./check_ha_leader.sh yba.dev.yugabyte.com
HA Leader (Primary)
Why This Matters
• Operational Clarity: Quickly confirm if an instance is serving as primary or standby without digging through complex logs or dashboards.
• Automation-Friendly: Integrate this script into monitoring systems, deployment pipelines, or failover controls.
• Complements yba-ctl: It fills the gap left by the yba-ctl tool, giving teams the visibility needed to make HA-aware decisions.
By combining the installation and management power of yba-ctl with this API-driven script, you now gain full visibility into your YBA instance roles!
Have Fun!
Our chipmunk neighbor peeks out from his cozy hideaway, waiting for the coast to clear before collecting the seeds dropped from the bird feeder.🐿️🌾