forked from lightbend/spark-history-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
executable file
·143 lines (129 loc) · 3.55 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# echo commands to the terminal output
set -ex
enablePVC=
enableGCS=
gcloudKey=
enableS3=
enableIAM=
accessKeyName=
secretKeyName=
eventsDir=
function usage {
cat<< EOF
Usage: entrypoint.sh [OPTIONS]
Options:
--pvc Enable PVC
--gcs gcloudkey Enable GCS and provide the Google Cloud key
--s3 enableIAM accessKeyName secretKeyName Enable S3 and configure whether IAM is enabled,
the accessKeyName and secretKeyName
-h | --help Prints this message.
EOF
}
function parse_args {
while [[ $# -gt 0 ]]
do
case "$1" in
--pvc)
enablePVC=true
shift
continue
;;
--gcs)
enableGCS=true
if [[ -n "$2" ]]; then
gcloudKey=$2
shift 2
continue
else
printf '"--gcs" requires a non-empty option argument.\n'
usage
exit 1
fi
;;
--s3)
if [[ -n "$4" ]]; then
enableS3=true
enableIAM=$2
accessKeyName=$3
secretKeyName=$4
shift 4
continue
else
printf '"--enableS3" require three non-empty option arguments.\n'
usage
exit 1
fi
;;
--events-dir)
if [[ -n "$2" ]]; then
eventsDir=$2
shift 2
continue
else
printf '"--events-dir" requires a non-empty option argument.\n'
usage
exit 1
fi
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
'')
break
;;
*)
printf "Unrecognized option: $1\n"
exit 1
;;
esac
shift
done
}
parse_args "$@"
# Check whether there is a passwd entry for the container UID
uid=$(id -u)
gid=$(id -g)
# turn off -e for getent because it will return error code in anonymous uid case
set +e
uid_entry=$(getent passwd ${uid})
set -e
# If there is no passwd entry for the container UID, attempt to create one
if [[ -z "${uid_entry}" ]] ; then
if [[ -w /etc/passwd ]] ; then
echo "$uid:x:$uid:$gid:anonymous uid:${SPARK_HOME}:/bin/false" >> /etc/passwd
else
echo "Container entrypoint.sh failed to add passwd entry for anonymous UID"
fi
fi
if [[ "$enablePVC" == "true" ]]; then
export SPARK_HISTORY_OPTS="$SPARK_HISTORY_OPTS \
-Dspark.history.fs.logDirectory=file:/mnt/$eventsDir";
elif [[ "$enableGCS" == "true" ]]; then
if [[ -n ${gcloudKey} ]]; then
export SPARK_HISTORY_OPTS="$SPARK_HISTORY_OPTS \
-Dspark.hadoop.google.cloud.auth.service.account.json.keyfile=/etc/secrets/$gcloudKey \
-Dspark.history.fs.logDirectory=$eventsDir";
else
echo "Please pass your Google Cloud Key!"
exit 1
fi
elif [[ "$enableS3" == "true" ]]; then
export SPARK_HISTORY_OPTS="$SPARK_HISTORY_OPTS \
-Dspark.history.fs.logDirectory=$eventsDir
-Dspark.hadoop.fs.s3a.impl=org.apache.hadoop.fs.s3a.S3AFileSystem";
if [[ "$enableIAM" == "false" ]]; then
export SPARK_HISTORY_OPTS="$SPARK_HISTORY_OPTS \
-Dspark.hadoop.fs.s3a.access.key=$(cat /etc/secrets/${accessKeyName}) \
-Dspark.hadoop.fs.s3a.secret.key=$(cat /etc/secrets/${secretKeyName})";
fi;
else
export SPARK_HISTORY_OPTS="$SPARK_HISTORY_OPTS \
-Dspark.history.fs.logDirectory=$eventsDir";
fi;
exec /sbin/tini -s -- /opt/spark/bin/spark-class org.apache.spark.deploy.history.HistoryServer