2009-11-14 09:11:53 -05:00
|
|
|
#!/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
|
|
|
|
|
2009-11-26 03:42:32 -05:00
|
|
|
type=$MASTER_INSTANCE_TYPE
|
|
|
|
[ -z "$type" ] && type=$SLAVE_INSTANCE_TYPE
|
|
|
|
arch=$MASTER_ARCH
|
|
|
|
[ -z "$arch" ] && arch=$SLAVE_ARCH
|
|
|
|
|
2009-11-14 09:11:53 -05:00
|
|
|
echo "Testing for existing master in group: $CLUSTER"
|
2009-11-17 03:00:24 -05:00
|
|
|
MASTER_EC2_HOST=`ec2-describe-instances $TOOL_OPTS | awk '"RESERVATION" == $1 && "'$CLUSTER_MASTER'" == $4, "RESERVATION" == $1 && "'$CLUSTER_MASTER'" != $4'`
|
2009-11-14 09:11:53 -05:00
|
|
|
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"
|
2009-11-17 03:00:24 -05:00
|
|
|
MASTER_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_EC2_HOST | awk '{print $5}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
|
|
|
|
echo $MASTER_EC2_HOST > $MASTER_IP_PATH
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Finding HBase image
|
2009-11-26 13:54:14 -05:00
|
|
|
[ -z "$AMI_IMAGE" ] && AMI_IMAGE=`ec2-describe-images $TOOL_OPTS -a | grep $S3_BUCKET | grep $HBASE_VERSION-$arch | grep available | awk '{print $2}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Start a master
|
2009-11-26 03:00:02 -05:00
|
|
|
echo "Starting master with AMI $AMI_IMAGE (arch $arch)"
|
2009-11-14 09:11:53 -05:00
|
|
|
# Substituting zookeeper quorum
|
|
|
|
ZOOKEEPER_QUORUM=`cat $ZOOKEEPER_QUORUM_PATH`
|
|
|
|
sed -e "s|%ZOOKEEPER_QUORUM%|$ZOOKEEPER_QUORUM|" \
|
2009-12-18 18:28:00 -05:00
|
|
|
-e "s|%EXTRA_PACKAGES%|$EXTRA_PACKAGES|" \
|
2009-11-14 09:11:53 -05:00
|
|
|
"$bin"/$USER_DATA_FILE > "$bin"/$USER_DATA_FILE.master
|
2009-11-26 03:00:02 -05:00
|
|
|
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}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
echo -n "Waiting for instance $INSTANCE to start"
|
|
|
|
while true; do
|
|
|
|
printf "."
|
|
|
|
# get private dns
|
2009-11-17 03:00:24 -05:00
|
|
|
MASTER_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep running | awk '{print $5}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
if [ ! -z $MASTER_HOST ]; then
|
|
|
|
echo " Started as $MASTER_HOST"
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
rm -f "$bin"/$USER_DATA_FILE.master
|
|
|
|
|
2009-11-17 03:00:24 -05:00
|
|
|
MASTER_EC2_HOST=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $4}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
|
|
|
|
echo $MASTER_EC2_HOST > $MASTER_IP_PATH
|
2009-11-17 03:00:24 -05:00
|
|
|
MASTER_EC2_ZONE=`ec2-describe-instances $TOOL_OPTS $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $11}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
echo $MASTER_EC2_ZONE > $MASTER_ZONE_PATH
|
|
|
|
|
|
|
|
while true; do
|
2009-11-19 13:45:06 -05:00
|
|
|
REPLY=`ssh $SSH_OPTS "root@$MASTER_EC2_HOST" 'echo "hello"'`
|
2009-11-14 09:11:53 -05:00
|
|
|
if [ ! -z $REPLY ]; then
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2009-12-05 19:31:36 -05:00
|
|
|
scp $SSH_OPTS $EC2_ROOT_SSH_KEY "root@$MASTER_EC2_HOST:/root/.ssh/id_rsa"
|
2009-11-19 13:45:06 -05:00
|
|
|
ssh $SSH_OPTS "root@$MASTER_EC2_HOST" "chmod 600 /root/.ssh/id_rsa"
|
|
|
|
|
2009-11-14 09:11:53 -05:00
|
|
|
MASTER_IP=`dig +short $MASTER_EC2_HOST`
|
|
|
|
echo "Master is $MASTER_EC2_HOST, ip is $MASTER_IP, zone is $MASTER_EC2_ZONE."
|