Skip to content

Instantly share code, notes, and snippets.

@salekseev
Last active October 15, 2017 20:22
Show Gist options
  • Save salekseev/3c9d1c344f7bf25f94a4 to your computer and use it in GitHub Desktop.
Save salekseev/3c9d1c344f7bf25f94a4 to your computer and use it in GitHub Desktop.
Script to check that both NameNodes are alive in HDFS HA configuration and will force failover to the preferred NameNode
#!/bin/bash
#
# This script will check that both NameNodes are alive in HDFS HA
# configuration and will force failover to the preferred NameNode.
#
# Author: Stas Alekseev <me@salekseev.com>
#
ACTIVE_NAMENODE=nn1
STANDBY_NAMENODE=nn2
if [ ${USER} != "hdfs" ]; then
echo "This script must be run as hdfs user."
exit 1
fi
# Check that both NameNodes are alive
hdfs haadmin -checkHealth ${ACTIVE_NAMENODE} && hdfs haadmin -checkHealth ${STANDBY_NAMENODE} || {
printf '%s\n' 'ERROR: one of the namenodes is dead'
exit 1
}
if [ $(hdfs haadmin -getServiceState ${ACTIVE_NAMENODE}) = "standby" ]
then
hdfs haadmin -failover ${STANDBY_NAMENODE} ${ACTIVE_NAMENODE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment