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.
|
|
|
|
|
|
|
|
# Create a HBase AMI.
|
|
|
|
# Inspired by Jonathan Siegel's EC2 script (http://blogsiegel.blogspot.com/2006/08/sandboxing-amazon-ec2.html)
|
|
|
|
|
2009-11-26 03:00:02 -05:00
|
|
|
# allow override of SLAVE_INSTANCE_TYPE from the command line
|
|
|
|
[ ! -z $1 ] && SLAVE_INSTANCE_TYPE=$1
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Import variables
|
|
|
|
bin=`dirname "$0"`
|
|
|
|
bin=`cd "$bin"; pwd`
|
|
|
|
. "$bin"/hbase-ec2-env.sh
|
|
|
|
|
2009-11-26 03:00:02 -05:00
|
|
|
type=$SLAVE_INSTANCE_TYPE
|
|
|
|
arch=$SLAVE_ARCH
|
2009-11-14 09:11:53 -05:00
|
|
|
|
2009-11-26 03:00:02 -05:00
|
|
|
echo "INSTANCE_TYPE is $type"
|
|
|
|
echo "ARCH is $arch"
|
|
|
|
|
2009-11-26 13:54:14 -05:00
|
|
|
AMI_IMAGE=`ec2-describe-images $TOOL_OPTS -a | grep $S3_BUCKET | grep hbase | grep $HBASE_VERSION-$arch | grep available | awk '{print $2}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
[ ! -z $AMI_IMAGE ] && echo "AMI already registered, use: ec2-deregister $AMI_IMAGE" && exit 1
|
|
|
|
|
|
|
|
echo "Starting a AMI with ID $BASE_AMI_IMAGE."
|
2009-11-26 03:00:02 -05:00
|
|
|
OUTPUT=`ec2-run-instances $BASE_AMI_IMAGE $TOOL_OPTS -k root -t $type`
|
2009-11-14 09:11:53 -05:00
|
|
|
BOOTING_INSTANCE=`echo $OUTPUT | awk '{print $6}'`
|
|
|
|
|
|
|
|
echo "Instance is $BOOTING_INSTANCE."
|
|
|
|
|
2009-11-17 03:00:24 -05:00
|
|
|
echo "Polling server status"
|
2009-11-14 09:11:53 -05:00
|
|
|
while true; do
|
|
|
|
printf "."
|
2009-11-17 03:00:24 -05:00
|
|
|
HOSTNAME=`ec2-describe-instances $TOOL_OPTS $BOOTING_INSTANCE | grep running | awk '{print $4}'`
|
2009-11-14 09:11:53 -05:00
|
|
|
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"
|
2009-12-02 00:25:12 -05:00
|
|
|
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
|
2009-11-14 09:11:53 -05:00
|
|
|
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)
|
2009-11-16 15:00:57 -05:00
|
|
|
scp $SSH_OPTS $EC2_PRIVATE_KEY "root@$HOSTNAME:/mnt"
|
|
|
|
scp $SSH_OPTS $EC2_CERT "root@$HOSTNAME:/mnt"
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Connect to it
|
2009-11-26 03:00:02 -05:00
|
|
|
ssh $SSH_OPTS "root@$HOSTNAME" "sh -c \"INSTANCE_TYPE=$type ARCH=$arch /mnt/create-hbase-image-remote\""
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
# Register image
|
2009-11-26 03:00:02 -05:00
|
|
|
ec2-register $TOOL_OPTS $S3_BUCKET/hbase-$HBASE_VERSION-$arch.manifest.xml
|
2009-11-14 09:11:53 -05:00
|
|
|
|
|
|
|
echo "Terminate with: ec2-terminate-instances $BOOTING_INSTANCE"
|