#!/bin/sh ######################################################### # # # Written 12/17/08 by Jeff Schroeder ## ######################################################### # # # # # keepalived-query.sh - Query the currently running # # # keepalived instance and print # # # running status and ip address # # # # # ########################################################## # $Id$ if [ ! -f /etc/keepalived/keepalived.conf ]; then echo "Keepalived not installed or properly configured" >&2 exit 1 fi config=/etc/keepalived/keepalived.conf status=$(basename $(ls /var/run/{MASTER,BACKUP} 2>/dev/null) 2>/dev/null) interface=$(awk '/[\t ]+interface /{print $NF}' $config) track_int=$(awk '{if ($1 == "track_interface") {getline;print $NF}}' $config) num_aliases=$(ip addr show | sed -rn "/${interface}/,/^[0-9]+: [a-z]+[0-9]+:/p" | grep -c inet) if [ $num_aliases = 2 ]; then vip=$(ip addr show | sed -rn "/${interface}/,/^[0-9]+: [a-z]+[0-9]+:/p" | \ awk '/inet/{if ($3 != "brd") print $2}' | \ sed -re 's:/[0-9]{2}$::') else vip="UNKNOWN" fi if ! ifconfig | grep -q ^$track_int; then echo "Track interface $track_int is down. This server is in maintenance mode" else echo "${status:-UNKNOWN} state with a vip of $vip on ${interface:-UNKNOWN}" fi