97 lines
3.5 KiB
Bash
Executable File
97 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Launch an EC2 HBase master.
|
|
|
|
if [ -z $1 ]; then
|
|
echo "Cluster name required!"
|
|
exit 1
|
|
fi
|
|
|
|
CLUSTER=$1
|
|
|
|
# Import variables
|
|
bin=`dirname "$0"`
|
|
bin=`cd "$bin"; pwd`
|
|
. "$bin"/hbase-ec2-env.sh
|
|
|
|
if [ -z $AWS_ACCOUNT_ID ]; then
|
|
echo "Please set AWS_ACCOUNT_ID in $bin/hbase-ec2-env.sh."
|
|
exit 1
|
|
fi
|
|
|
|
type=$MASTER_INSTANCE_TYPE
|
|
[ -z "$type" ] && type=$SLAVE_INSTANCE_TYPE
|
|
arch=$MASTER_ARCH
|
|
[ -z "$arch" ] && arch=$SLAVE_ARCH
|
|
|
|
echo "Testing for existing master in group: $CLUSTER"
|
|
MASTER_EC2_HOST=`ec2-describe-instances $TOOL_OPTS | awk '"RESERVATION" == $1 && "'$CLUSTER_MASTER'" == $4, "RESERVATION" == $1 && "'$CLUSTER_MASTER'" != $4'`
|
|
MASTER_EC2_HOST=`echo "$MASTER_EC2_HOST" | awk '"INSTANCE" == $1 && "running" == $6 {print $4}'`
|
|
|
|
if [ ! -z "$MASTER_EC2_HOST" ]; then
|
|
echo "Master already running on: $MASTER_EC2_HOST"
|
|
MASTER_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_EC2_HOST | awk '{print $5}'`
|
|
echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
|
|
echo $MASTER_EC2_HOST > $MASTER_IP_PATH
|
|
exit 0
|
|
fi
|
|
|
|
# Finding HBase image
|
|
[ -z "$AMI_IMAGE" ] && AMI_IMAGE=`ec2-describe-images $TOOL_OPTS -a | grep $S3_BUCKET | grep $HBASE_VERSION-$arch | grep available | awk '{print $2}'`
|
|
|
|
# Start a master
|
|
echo "Starting master with AMI $AMI_IMAGE (arch $arch)"
|
|
# Substituting zookeeper quorum
|
|
ZOOKEEPER_QUORUM=`cat $ZOOKEEPER_QUORUM_PATH`
|
|
sed -e "s|%ZOOKEEPER_QUORUM%|$ZOOKEEPER_QUORUM|" \
|
|
-e "s|%EXTRA_PACKAGES%|$EXTRA_PACKAGES|" \
|
|
"$bin"/$USER_DATA_FILE > "$bin"/$USER_DATA_FILE.master
|
|
INSTANCE=`ec2-run-instances $AMI_IMAGE $TOOL_OPTS -n 1 -g $CLUSTER_MASTER -k root -f "$bin"/$USER_DATA_FILE.master -t $type | grep INSTANCE | awk '{print $2}'`
|
|
echo -n "Waiting for instance $INSTANCE to start"
|
|
while true; do
|
|
printf "."
|
|
# get private dns
|
|
MASTER_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep running | awk '{print $5}'`
|
|
if [ ! -z $MASTER_HOST ]; then
|
|
echo " Started as $MASTER_HOST"
|
|
break;
|
|
fi
|
|
sleep 1
|
|
done
|
|
rm -f "$bin"/$USER_DATA_FILE.master
|
|
|
|
MASTER_EC2_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $4}'`
|
|
echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
|
|
echo $MASTER_EC2_HOST > $MASTER_IP_PATH
|
|
MASTER_EC2_ZONE=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $11}'`
|
|
echo $MASTER_EC2_ZONE > $MASTER_ZONE_PATH
|
|
|
|
while true; do
|
|
REPLY=`ssh $SSH_OPTS "root@$MASTER_EC2_HOST" 'echo "hello"'`
|
|
if [ ! -z $REPLY ]; then
|
|
break;
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
scp $SSH_OPTS $EC2_ROOT_SSH_KEY "root@$MASTER_EC2_HOST:/root/.ssh/id_rsa"
|
|
ssh $SSH_OPTS "root@$MASTER_EC2_HOST" "chmod 600 /root/.ssh/id_rsa"
|
|
|
|
MASTER_IP=`dig +short $MASTER_EC2_HOST`
|
|
echo "Master is $MASTER_EC2_HOST, ip is $MASTER_IP, zone is $MASTER_EC2_ZONE."
|