source: proiecte/HadoopJUnit/hadoop-0.20.1/src/contrib/ec2/bin/launch-hadoop-master @ 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: 4.5 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# Launch an EC2 Hadoop master.
19
20if [ -z $1 ]; then
21  echo "Cluster name required!"
22  exit -1
23fi
24
25CLUSTER=$1
26
27# Import variables
28bin=`dirname "$0"`
29bin=`cd "$bin"; pwd`
30. "$bin"/hadoop-ec2-env.sh
31
32if [ -z $AWS_ACCOUNT_ID ]; then
33  echo "Please set AWS_ACCOUNT_ID in $bin/hadoop-ec2-env.sh."
34  exit -1
35fi
36
37echo "Testing for existing master in group: $CLUSTER"
38MASTER_EC2_HOST=`ec2-describe-instances | awk '"RESERVATION" == $1 && "'$CLUSTER_MASTER'" == $4, "RESERVATION" == $1 && "'$CLUSTER_MASTER'" != $4'`
39MASTER_EC2_HOST=`echo "$MASTER_EC2_HOST" | awk '"INSTANCE" == $1 && "running" == $6 {print $4}'`
40
41if [ ! -z "$MASTER_EC2_HOST" ]; then
42  echo "Master already running on: $MASTER_EC2_HOST"
43  MASTER_HOST=`ec2-describe-instances $INSTANCE | grep INSTANCE | grep running | grep $MASTER_EC2_HOST | awk '{print $5}'`
44  echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
45  echo $MASTER_EC2_HOST > $MASTER_IP_PATH
46  exit 0
47fi
48
49ec2-describe-group | egrep "[[:space:]]$CLUSTER_MASTER[[:space:]]" > /dev/null
50if [ ! $? -eq 0 ]; then
51  echo "Creating group $CLUSTER_MASTER"
52  ec2-add-group $CLUSTER_MASTER -d "Group for Hadoop Master."
53  ec2-authorize $CLUSTER_MASTER -o $CLUSTER_MASTER -u $AWS_ACCOUNT_ID
54  ec2-authorize $CLUSTER_MASTER -p 22    # ssh
55
56  if [ $ENABLE_WEB_PORTS == "true" ]; then
57    ec2-authorize $CLUSTER_MASTER -p 50030 # JobTracker web interface
58    ec2-authorize $CLUSTER_MASTER -p 50060 # TaskTracker web interface
59    ec2-authorize $CLUSTER_MASTER -p 50070 # NameNode web interface
60    ec2-authorize $CLUSTER_MASTER -p 50075 # DataNode web interface
61  fi
62fi
63
64ec2-describe-group | egrep "[[:space:]]$CLUSTER[[:space:]]" > /dev/null
65if [ ! $? -eq 0 ]; then
66  echo "Creating group $CLUSTER"
67  ec2-add-group $CLUSTER -d "Group for Hadoop Slaves."
68  ec2-authorize $CLUSTER -o $CLUSTER -u $AWS_ACCOUNT_ID
69  ec2-authorize $CLUSTER -p 22    # ssh
70
71  if [ $ENABLE_WEB_PORTS == "true" ]; then
72    ec2-authorize $CLUSTER -p 50030 # JobTracker web interface
73    ec2-authorize $CLUSTER -p 50060 # TaskTracker web interface
74    ec2-authorize $CLUSTER -p 50070 # NameNode web interface
75    ec2-authorize $CLUSTER -p 50075 # DataNode web interface
76  fi
77
78  ec2-authorize $CLUSTER_MASTER -o $CLUSTER -u $AWS_ACCOUNT_ID
79  ec2-authorize $CLUSTER -o $CLUSTER_MASTER -u $AWS_ACCOUNT_ID
80fi
81
82# Finding Hadoop image
83AMI_IMAGE=`ec2-describe-images -a | grep $S3_BUCKET | grep $HADOOP_VERSION | grep $ARCH | grep available | awk '{print $2}'`
84
85# Start a master
86echo "Starting master with AMI $AMI_IMAGE"
87USER_DATA="MASTER_HOST=master,MAX_MAP_TASKS=$MAX_MAP_TASKS,MAX_REDUCE_TASKS=$MAX_REDUCE_TASKS,COMPRESS=$COMPRESS"
88INSTANCE=`ec2-run-instances $AMI_IMAGE -n 1 -g $CLUSTER_MASTER -k $KEY_NAME -f "$bin"/$USER_DATA_FILE -t $INSTANCE_TYPE $KERNEL_ARG | grep INSTANCE | awk '{print $2}'`
89echo "Waiting for instance $INSTANCE to start"
90while true; do
91  printf "."
92  # get private dns
93  MASTER_HOST=`ec2-describe-instances $INSTANCE | grep running | awk '{print $5}'`
94  if [ ! -z $MASTER_HOST ]; then
95    echo "Started as $MASTER_HOST"
96    break;
97  fi
98  sleep 1
99done
100
101MASTER_EC2_HOST=`ec2-describe-instances $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $4}'`
102echo $MASTER_HOST > $MASTER_PRIVATE_IP_PATH
103echo $MASTER_EC2_HOST > $MASTER_IP_PATH
104MASTER_EC2_ZONE=`ec2-describe-instances $INSTANCE | grep INSTANCE | grep running | grep $MASTER_HOST | awk '{print $11}'`
105echo $MASTER_EC2_ZONE > $MASTER_ZONE_PATH
106
107while true; do
108  REPLY=`ssh $SSH_OPTS "root@$MASTER_EC2_HOST" 'echo "hello"'`
109  if [ ! -z $REPLY ]; then
110   break;
111  fi
112  sleep 5
113done
114
115echo "Copying private key to master"
116scp $SSH_OPTS $PRIVATE_KEY_PATH "root@$MASTER_EC2_HOST:/root/.ssh/id_rsa"
117ssh $SSH_OPTS "root@$MASTER_EC2_HOST" "chmod 600 /root/.ssh/id_rsa"
118
119MASTER_IP=`dig +short $MASTER_EC2_HOST`
120echo "Master is $MASTER_EC2_HOST, ip is $MASTER_IP, zone is $MASTER_EC2_ZONE."
Note: See TracBrowser for help on using the repository browser.