-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·60 lines (49 loc) · 2.92 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
#!/usr/bin/env bash
# Translates relevant docker environment values
# to configure.rb parameters
# ----------------------------------------------
# Allow parameters to configure.rb to come from CONFIGURE_PARAMS as opposed to stdin
# This is to support parameterizing via Compose in particular. The two lines below are equivalent in effect:
# docker run -e "CONFIGURE_PARAMS=cassandra --dc daas-1 --calculate-tokens 1:1" -ti --name c1 --rm andlaz/hadoop-cassandra
# docker run -ti --name c1 --rm andlaz/hadoop-cassandra cassandra --dc daas-1 --calculate-tokens 1:1
P=${CONFIGURE_PARAMS:-$(echo $*)}
set -- $P
add_cassandra_options () {
local opts=""
# if --seed is not set, set it to the alias host
if [ ! $SEED_NAME ] && [[ $* != *"--seeds"* ]]; then opts="$opts --seeds "$(ip route get 255.255.255.255 | grep -Po '(?<=src )(\d{1,3}.){4}');
elif [ $SEED_NAME ] && [[ $* != *"--seeds"* ]]; then opts="$opts --seeds seed"; fi
# if --listen-address is not set, set it to $HOSTNAME
if [ $HOSTNAME ] && [[ $* != *"--listen-address"* ]]; then opts="$opts --listen-address $HOSTNAME"; fi
# if --rpc-address is not set, set it to $HOSTNAME
if [ $HOSTNAME ] && [[ $* != *"--rpc-address"* ]]; then opts="$opts --rpc-address $HOSTNAME"; fi
if [ $OPSCENTER_NAME ] && [[ $* != *"--opscenter"* ]]; then opts="$opts --opscenter opscenter:61620"; fi
echo $opts
}
add_datanode_options () {
local opts=""
# if --name-node is not set, set it to the docker alias host
if [ $NAMENODE_NAME ] && [ ! "$*" == *"--name-node"* ]; then opts="$opts --name-node namenode"; fi
echo $opts
}
add_nodemanager_options () {
local opts=""
# if --resource-manager is not set, set it to the docker alias host
if [ $RESOURCEMANAGER_NAME ] && [[ "$*" != *"--resource-manager"* ]]; then opts="$opts --resource-manager resourcemanager"; fi
if [ $HOSTNAME ] && [[ "$*" != *"--web-ui-host"* ]]; then opts="$opts --web-ui-host $HOSTNAME"; fi
echo $opts
}
case $1 in
all) ruby /root/configure.rb $* `add_cassandra_options $*` `add_datanode_options $*` `add_nodemanager_options $*` && supervisord -c /etc/supervisord.conf ;;
cassandra) ruby /root/configure.rb $* `add_cassandra_options $*` && supervisord -c /etc/supervisord.conf ;;
datanode) ruby /root/configure.rb $* `add_datanode_options $*` && supervisord -c /etc/supervisord.conf ;;
nodemanager) ruby /root/configure.rb $* `add_nodemanager_options $*` && supervisord -c /etc/supervisord.conf ;;
help) cat << EOM
The image's entry point script will populate the following -parameters from linked
containers and Docker environment variables:
EOM
echo -e "\ncassandra\t:" `add_cassandra_options $*` "\ndatanode\t:" `add_datanode_options $*` "\nnodemanager\t:" `add_nodemanager_options $*`
echo -e "\n( Cassandra seed, HDFS NameNode and YARN ResourceManager countainers need to be linked under the aliases "seed", "namenode" and "resourcemanager" for this to happen. )\n"
ruby /root/configure.rb $* ;;
*) ruby /root/configure.rb $*
esac