/
create-hbase-image
executable file
·98 lines (78 loc) · 3.18 KB
/
create-hbase-image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/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
[ ! -z $2 ] && HADOOP_ARCHIVE=$2
[ ! -z $3 ] && HBASE_ARCHIVE=$3
# 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 local hadoop and hbase packages, if specified
if [ ! -z $HADOOP_ARCHIVE ];
then
scp $SSH_OPTS $HADOOP_ARCHIVE "root@$HOSTNAME:/usr/local"
fi
if [ ! -z $HBASE_ARCHIVE ];
then
scp $SSH_OPTS $HBASE_ARCHIVE "root@$HOSTNAME:/usr/local"
fi
# 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 /mnt/create-hbase-image-remote\""
# Register image
ec2-register $TOOL_OPTS -n hbase-$REGION-$HBASE_VERSION-$arch $S3_BUCKET/hbase-$HBASE_VERSION-$arch.manifest.xml
echo "Terminate with: ec2-terminate-instances $BOOTING_INSTANCE"