Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Last active December 17, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashrithr/5588821 to your computer and use it in GitHub Desktop.
Save ashrithr/5588821 to your computer and use it in GitHub Desktop.
Script to start hbase with ssh on mac
#!/usr/bin/env bash
# ===
# Script to start hbase also handles starting/stopping osx's ssh as a dependecy
# Author: Ashrith
# ===
HBASE_START_SCRIPT="/Users/ashrith/HADOOP/hbase/bin/start-hbase.sh"
HBASE_STOP_SCRIPT="/Users/ashrith/HADOOP/hbase/bin/stop-hbase.sh"
function usage () {
echo "Usage: `basename $0` start | stop | stop_ssh"
exit 1
}
if ! [[ $# = 1 ]]; then
usage
fi
if ! [[ `uname` == "Darwin" ]]; then
echo "Only works on Mac OSX" && exit 1
fi
SSH_STATUS=`systemsetup -getremotelogin | awk '{print $3}'`
HBASE_STATUS=`jps | grep HMaster`
if [[ $1 == "start" ]]; then
# check if remotessh is truned on, if not turn ssh on
if [[ $SSH_STATUS == "Off" ]]; then
echo "Is seems like ssh is not running"
echo "Starting SSH ..."
systemsetup -setremotelogin on
[ $? -ne 0 ] && ( echo "Starting SSH ... [FAILED] , aborting" && exit 1 ) || echo "Starting SSH ... [OK]"
fi
#check for hbase process
if [[ -z $HBASE_STATUS ]]; then
echo "Starting HBase ..."
$HBASE_START_SCRIPT
[ $? -ne 0 ] && ( echo "Starting HBase ... [FAILED]" && exit 1 ) || echo "Starting HBase ... [OK]"
else
echo "HBase master is already running"
exit 0
fi
elif [[ $1 == "stop" ]]; then
if [[ -z $HBASE_STATUS ]]; then
echo "No HBaseMsater found to stop"
exit 0
else
echo "Stopping HBase ..."
$HBASE_STOP_SCRIPT
[ $? -ne 0 ] && ( echo "Stopping HBase ... [FAILED]" && exit 1 ) || echo "Stopping HBase ... [OK]"
fi
echo "Stopping SSH ..."
systemsetup -setremotelogin off <<<yes
echo ""
echo "Stopping SSH ... [OK]"
elif [[ $1 == "stop_ssh" ]]; then
echo "Stopping SSH ..."
systemsetup -setremotelogin off <<<yes
echo ""
echo "Stopping SSH ..."
else
echo "Unknown Options $1"
usage
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment