85 lines
2.9 KiB
Bash
Executable File
85 lines
2.9 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.
|
|
|
|
# Create a HBase AMI.
|
|
# Inspired by Jonathan Siegel's EC2 script (http://blogsiegel.blogspot.com/2006/08/sandboxing-amazon-ec2.html)
|
|
|
|
# allow override of SLAVE_INSTANCE_TYPE from the command line
|
|
[ ! -z $1 ] && SLAVE_INSTANCE_TYPE=$1
|
|
|
|
# Import variables
|
|
bin=`dirname "$0"`
|
|
bin=`cd "$bin"; pwd`
|
|
. "$bin"/hbase-ec2-env.sh
|
|
|
|
type=$SLAVE_INSTANCE_TYPE
|
|
arch=$SLAVE_ARCH
|
|
|
|
echo "INSTANCE_TYPE is $type"
|
|
echo "ARCH is $arch"
|
|
|
|
AMI_IMAGE=`ec2-describe-images $TOOL_OPTS -a | grep $S3_BUCKET | grep hbase | grep $HBASE_VERSION-$arch | grep available | awk '{print $2}'`
|
|
|
|
[ ! -z $AMI_IMAGE ] && echo "AMI already registered, use: ec2-deregister $AMI_IMAGE" && exit 1
|
|
|
|
echo "Starting a AMI with ID $BASE_AMI_IMAGE."
|
|
OUTPUT=`ec2-run-instances $BASE_AMI_IMAGE $TOOL_OPTS -k root -t $type`
|
|
BOOTING_INSTANCE=`echo $OUTPUT | awk '{print $6}'`
|
|
|
|
echo "Instance is $BOOTING_INSTANCE."
|
|
|
|
echo "Polling server status"
|
|
while true; do
|
|
printf "."
|
|
HOSTNAME=`ec2-describe-instances $TOOL_OPTS $BOOTING_INSTANCE | grep running | awk '{print $4}'`
|
|
if [ ! -z $HOSTNAME ]; then
|
|
break;
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "The server is available at $HOSTNAME."
|
|
while true; do
|
|
REPLY=`ssh $SSH_OPTS "root@$HOSTNAME" 'echo "hello"'`
|
|
if [ ! -z $REPLY ]; then
|
|
break;
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
echo "Copying scripts."
|
|
|
|
# Copy setup scripts
|
|
scp $SSH_OPTS "$bin"/hbase-ec2-env.sh "root@$HOSTNAME:/mnt"
|
|
scp $SSH_OPTS "$bin"/functions.sh "root@$HOSTNAME:/mnt"
|
|
if [ -f "$bin"/credentials.sh ] ; then
|
|
scp $SSH_OPTS "$bin"/credentials.sh "root@$HOSTNAME:/mnt"
|
|
fi
|
|
scp $SSH_OPTS "$bin"/image/create-hbase-image-remote "root@$HOSTNAME:/mnt"
|
|
scp $SSH_OPTS "$bin"/image/ec2-run-user-data "root@$HOSTNAME:/etc/init.d"
|
|
|
|
# Copy private key and certificate (for bundling image)
|
|
scp $SSH_OPTS $EC2_PRIVATE_KEY "root@$HOSTNAME:/mnt"
|
|
scp $SSH_OPTS $EC2_CERT "root@$HOSTNAME:/mnt"
|
|
|
|
# Connect to it
|
|
ssh $SSH_OPTS "root@$HOSTNAME" "sh -c \"INSTANCE_TYPE=$type ARCH=$arch HBASE_URL=$HBASE_URL HADOOP_URL=$HADOOP_URL LZO_URL=$LZO_URL JAVA_URL=$JAVA_URL /mnt/create-hbase-image-remote\""
|
|
|
|
# Register image
|
|
ec2-register $TOOL_OPTS $S3_BUCKET/hbase-$HBASE_VERSION-$arch.manifest.xml
|
|
|
|
echo "Terminate with: ec2-terminate-instances $BOOTING_INSTANCE"
|