-
Notifications
You must be signed in to change notification settings - Fork 6
/
entrypoint.sh
executable file
·67 lines (52 loc) · 1.57 KB
/
entrypoint.sh
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
#!/bin/bash
# Script locates ip for a namenode to bind to. Generates config and starts namenode/datanode.
# expects: HADOOP_HOME, HADOOP_HDFS_USER
# hadoop-env.sh is not used!!! If env should be passed the propper way
# is to use docker --env-file option.
: ${HADOOP_HOME:?Must be provided\!}
: ${HADOOP_HDFS_USER:?Must be provided\!}
export HADOOP_NAMENODE_ADDRESS
# Pick up Namenode address
setup_namenode() {
export HADOOP_NAMENODE_BINDIF=${HADOOP_NAMENODE_BINDIF:-eth0}
if [ -z "$HADOOP_NAMENODE_ADDRESS" ]; then
cidr_ip=$(ip a show $HADOOP_NAMENODE_BINDIF | grep "inet " | tr -s ' ' | cut -f 3 -d' ')
HADOOP_NAMENODE_ADDRESS="${cidr_ip%/*}"
fi
}
# Set Hadoop directories owner
chown_volume() {
paths="/hadoop/dfs/name /hadoop/dfs/sname1 /hadoop/dfs/data1"
mkdir -p ${paths}
chown ${HADOOP_HDFS_USER}:${HADOOP_HDFS_USER} ${paths}
}
# Setup before handing off to the Hadoop binary
setup() {
fail=$1
[ -z "$fail" ] || : ${HADOOP_NAMENODE_ADDRESS:?Must be provided\!}
# write core-site.xml and hdfs-site.xml
confd -onetime -backend env
# chown directories
chown_volume
}
## Sleep before starting up
#
sleep ${WAITFORSTART:-0}
## Handle startup behavior
#
case $1 in
hdfs)
# Namenode picks its address automatically
shift
[ "$1" != "namenode" ] || setup_namenode
setup fail
exec gosu $HADOOP_HDFS_USER $HADOOP_HOME/bin/hdfs $@
;;
*)
setup
# Start helper script if any (exec without dropping privileges)
[ -x "/$1.sh" ] && exec "/$1.sh"
# Run a random command as Hadoop user
exec gosu $HADOOP_HDFS_USER $@
;;
esac