source: proiecte/HadoopJUnit/hadoop-0.20.1/src/contrib/ec2/bin/create-hadoop-image @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#!/usr/bin/env bash
2
3# Licensed to the Apache Software Foundation (ASF) under one or more
4# contributor license agreements.  See the NOTICE file distributed with
5# this work for additional information regarding copyright ownership.
6# The ASF licenses this file to You under the Apache License, Version 2.0
7# (the "License"); you may not use this file except in compliance with
8# the License.  You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18# Create a Hadoop AMI.
19# Inspired by Jonathan Siegel's EC2 script (http://blogsiegel.blogspot.com/2006/08/sandboxing-amazon-ec2.html)
20
21# Import variables
22bin=`dirname "$0"`
23bin=`cd "$bin"; pwd`
24. "$bin"/hadoop-ec2-env.sh
25
26AMI_IMAGE=`ec2-describe-images -a | grep $S3_BUCKET | grep $HADOOP_VERSION | grep $ARCH | grep available | awk '{print $2}'`
27
28[ ! -z $AMI_IMAGE ] && echo "AMI already registered, use: ec2-deregister $AMI_IMAGE" && exit -1
29
30echo "Starting a AMI with ID $BASE_AMI_IMAGE."
31OUTPUT=`ec2-run-instances $BASE_AMI_IMAGE -k $KEY_NAME -t $INSTANCE_TYPE`
32BOOTING_INSTANCE=`echo $OUTPUT | awk '{print $6}'`
33
34echo "Instance is $BOOTING_INSTANCE."
35
36echo "Polling server status (ec2-describe-instances $BOOTING_INSTANCE)"
37while true; do
38  printf "."
39  HOSTNAME=`ec2-describe-instances $BOOTING_INSTANCE | grep running | awk '{print $4}'`
40  if [ ! -z $HOSTNAME ]; then
41    break;
42  fi
43  sleep 1
44done
45
46echo "The server is available at $HOSTNAME."
47while true; do
48  REPLY=`ssh $SSH_OPTS "root@$HOSTNAME" 'echo "hello"'`
49  if [ ! -z $REPLY ]; then
50   break;
51  fi
52  sleep 5
53done
54
55#read -p "Login first? [yes or no]: " answer
56
57if [ "$answer" == "yes" ]; then
58  ssh $SSH_OPTS "root@$HOSTNAME"
59fi
60
61echo "Copying scripts."
62
63# Copy setup scripts
64scp $SSH_OPTS "$bin"/hadoop-ec2-env.sh "root@$HOSTNAME:/mnt"
65scp $SSH_OPTS "$bin"/image/create-hadoop-image-remote "root@$HOSTNAME:/mnt"
66scp $SSH_OPTS "$bin"/image/ec2-run-user-data "root@$HOSTNAME:/etc/init.d"
67
68# Copy private key and certificate (for bundling image)
69scp $SSH_OPTS $EC2_KEYDIR/pk*.pem "root@$HOSTNAME:/mnt"
70scp $SSH_OPTS $EC2_KEYDIR/cert*.pem "root@$HOSTNAME:/mnt"
71
72# Connect to it
73ssh $SSH_OPTS "root@$HOSTNAME" '/mnt/create-hadoop-image-remote'
74
75# Register image
76ec2-register $S3_BUCKET/hadoop-$HADOOP_VERSION-$ARCH.manifest.xml
77
78echo "Terminate with: ec2-terminate-instances $BOOTING_INSTANCE"
Note: See TracBrowser for help on using the repository browser.