-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
93 lines (73 loc) · 2.93 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
#!/usr/bin/env bash
set -e
export ENABLE_BUILT_IN_PLUGINS=flink-s3-fs-hadoop-1.16.2.jar
# fix for rocksb memory fragmentation issue
export LD_PRELOAD=$LD_PRELOAD:/usr/lib/x86_64-linux-gnu/libjemalloc.so
# If unspecified, the hostname of the container is taken as the JobManager address
#JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-$(hostname -f)}
CONF_FILE="${FLINK_HOME}/conf/flink-conf.yaml"
# This allows us to run standalone-job for local development
if [ "$IS_LOCAL_DEV" = "true" ]
then
cp ${FLINK_JOB_DIR}/flink-job.jar ${FLINK_HOME}/lib/flink-job.jar
if [ -n "${FLINK_PROPERTIES}" ]; then
echo "${FLINK_PROPERTIES}" >> "${CONF_FILE}"
fi
fi
#######################################################################################
# What follows is a modified form of the official flink-docker::/docker-entrypoint.sh #
#######################################################################################
COMMAND_STANDALONE="standalone-job"
drop_privs_cmd() {
if [ $(id -u) != 0 ]; then
# Don't need to drop privs if EUID != 0
return
elif [ -x /sbin/su-exec ]; then
# Alpine
echo su-exec flink
else
# Others
echo gosu flink
fi
}
copy_plugins_if_required() {
if [ -z "$ENABLE_BUILT_IN_PLUGINS" ]; then
return 0
fi
echo "Enabling required built-in plugins"
for target_plugin in $(echo "$ENABLE_BUILT_IN_PLUGINS" | tr ';' ' '); do
echo "Linking ${target_plugin} to plugin directory"
plugin_name=${target_plugin%.jar}
mkdir -p "${FLINK_HOME}/plugins/${plugin_name}"
if [ ! -e "${FLINK_HOME}/opt/${target_plugin}" ]; then
echo "Plugin ${target_plugin} does not exist. Exiting."
exit 1
else
ln -fs "${FLINK_HOME}/opt/${target_plugin}" "${FLINK_HOME}/plugins/${plugin_name}"
echo "Successfully enabled ${target_plugin}"
fi
done
}
prepare_job_manager_start() {
echo "Starting Job Manager"
copy_plugins_if_required
}
if [ "$1" = "help" ]; then
echo "Usage: $(basename "$0") (jobmanager|${COMMAND_STANDALONE}|taskmanager|help)"
exit 0
elif [ "$1" = "jobmanager" ]; then
shift 1
prepare_job_manager_start
exec $(drop_privs_cmd) "$FLINK_HOME/bin/jobmanager.sh" start-foreground "$@"
elif [ "$1" = ${COMMAND_STANDALONE} ]; then
shift 1
prepare_job_manager_start
exec $(drop_privs_cmd) "$FLINK_HOME/bin/standalone-job.sh" start-foreground -D"classloader.parent-first-patterns.additional=org.apache.flink.statefun;org.apache.kafka;com.google.protobuf" "$@"
elif [ "$1" = "taskmanager" ]; then
shift 1
echo "Starting Task Manager"
copy_plugins_if_required
TASK_MANAGER_NUMBER_OF_TASK_SLOTS=${TASK_MANAGER_NUMBER_OF_TASK_SLOTS:-$(grep -c ^processor /proc/cpuinfo)}
exec $(drop_privs_cmd) "$FLINK_HOME/bin/taskmanager.sh" start-foreground -D"classloader.parent-first-patterns.additional=org.apache.flink.statefun;org.apache.kafka;com.google.protobuf" "$@"
fi
exec "$@"