Skip to content

Commit 1320a46

Browse files
committed
Merge pull request #91 from voukka/SPARK-5246_voukka_resolving_hostname
Spark-5246 resolving hostname
2 parents 3a95101 + cb2c034 commit 1320a46

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ nosetests.xml
3333
.mr.developer.cfg
3434
.project
3535
.pydevproject
36+
37+
# JetBrains products
38+
.idea/

resolve-hostname.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Starting new instance in VPC often results that `hostname` returns something like 'ip-10-1-1-24', which is
4+
# not resolvable. Which leads to problems like SparkUI failing to bind itself on start up to that hostname as
5+
# described in https://issues.apache.org/jira/browse/SPARK-5246.
6+
# This script maps private ip to such hostname via '/etc/hosts'.
7+
#
8+
9+
# Are we in VPC?
10+
MAC=`wget -q -O - http://169.254.169.254/latest/meta-data/mac`
11+
VCP_ID=`wget -q -O - http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC}/vpc-id`
12+
if [ -z "${VCP_ID}" ]; then
13+
# echo "nothing to do - instance is not in VPC"
14+
exit 0
15+
fi
16+
17+
SHORT_HOSTNAME=`hostname`
18+
19+
PRIVATE_IP=`wget -q -O - http://169.254.169.254/latest/meta-data/local-ipv4`
20+
21+
# do changes only if short hostname does not resolve
22+
if [ ! ping -c 1 -q "${SHORT_HOSTNAME}" > /dev/null 2>&1 ]; then
23+
echo -e "\n ${PRIVATE_IP} ${SHORT_HOSTNAME}\n" >> /etc/hosts
24+
25+
# let's make sure that it got fixed
26+
if [ ! ping -c 1 -q "${SHORT_HOSTNAME}" > /dev/null 2>&1 ]; then
27+
# return some non-zero code to indicate problem
28+
echo "Possible bug: unable to fix resolution of local hostname"
29+
return 62
30+
fi
31+
32+
fi

setup-slave.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ source ec2-variables.sh
1414

1515
# Set hostname based on EC2 private DNS name, so that it is set correctly
1616
# even if the instance is restarted with a different private DNS name
17-
PRIVATE_DNS=`wget -q -O - http://instance-data.ec2.internal/latest/meta-data/local-hostname`
17+
PRIVATE_DNS=`wget -q -O - http://169.254.169.254/latest/meta-data/local-hostname`
1818
hostname $PRIVATE_DNS
1919
echo $PRIVATE_DNS > /etc/hostname
2020
HOSTNAME=$PRIVATE_DNS # Fix the bash built-in hostname variable too
2121

22+
bash /root/spark-ec2/resolve-hostname.sh
23+
2224
echo "Setting up slave on `hostname`..."
2325

2426
# Work around for R3 instances without pre-formatted ext3 disks

setup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ source ec2-variables.sh
2121

2222
# Set hostname based on EC2 private DNS name, so that it is set correctly
2323
# even if the instance is restarted with a different private DNS name
24-
PRIVATE_DNS=`wget -q -O - http://instance-data.ec2.internal/latest/meta-data/local-hostname`
25-
PUBLIC_DNS=`wget -q -O - http://instance-data.ec2.internal/latest/meta-data/hostname`
24+
PRIVATE_DNS=`wget -q -O - http://169.254.169.254/latest/meta-data/local-hostname`
25+
PUBLIC_DNS=`wget -q -O - http://169.254.169.254/latest/meta-data/hostname`
2626
hostname $PRIVATE_DNS
2727
echo $PRIVATE_DNS > /etc/hostname
2828
export HOSTNAME=$PRIVATE_DNS # Fix the bash built-in hostname variable too

0 commit comments

Comments
 (0)