-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·85 lines (72 loc) · 3.07 KB
/
docker-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
#!/usr/bin/dumb-init /bin/sh
set -e
# Note above that we run dumb-init as PID 1 in order to reap zombie processes
# as well as forward signals to all processes in its session. Normally, sh
# wouldn't do either of these functions so we'd leak zombies as well as do
# unclean termination of all our sub-processes.
# As of docker 1.13, using docker run --init achieves the same outcome.
# You can set NOMAD_BIND_INTERFACE to the name of the interface you'd like to
# bind to and this will look up the IP and pass the proper -bind= option along
# to Nomad.
NOMAD_BIND=
if [ -n "$NOMAD_BIND_INTERFACE" ]; then
NOMAD_BIND_ADDRESS=$(ip -o -4 addr list $NOMAD_BIND_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1)
if [ -z "$NOMAD_BIND_ADDRESS" ]; then
echo "Could not find IP for interface '$NOMAD_BIND_INTERFACE', exiting"
exit 1
fi
NOMAD_BIND="-bind=$NOMAD_BIND_ADDRESS"
echo "==> Found address '$NOMAD_BIND_ADDRESS' for interface '$NOMAD_BIND_INTERFACE', setting bind option..."
fi
# Addresses (HTTP, RPC and SERF) cannot be overiden through cli
# NOMAD_DATA_DIR is exposed as a volume for possible persistent storage. The
# NOMAD_CONFIG_DIR isn't exposed as a volume but you can compose additional
# config files in there if you use this image as a base, or use NOMAD_LOCAL_CONFIG
# below.
NOMAD_DATA_DIR=/nomad/data
NOMAD_CONFIG_DIR=/nomad/config
# You can also set the NOMAD_LOCAL_CONFIG environemnt variable to pass some
# Nomad configuration JSON without having to bind any volumes.
if [ -n "$NOMAD_LOCAL_CONFIG" ]; then
echo "$NOMAD_LOCAL_CONFIG" > "$NOMAD_CONFIG_DIR/local.json"
fi
# If the user is trying to run Nomad directly with some arguments, then
# pass them to Nomad.
if [ "${1:0:1}" = '-' ]; then
set -- nomad "$@"
fi
# Look for Nomad subcommands.
if [ "$1" = 'agent' ]; then
shift
set -- nomad agent \
-data-dir="$NOMAD_DATA_DIR" \
-config="$NOMAD_CONFIG_DIR" \
$NOMAD_BIND \
"$@"
elif [ "$1" = 'version' ]; then
# This needs a special case because there's no help output.
set -- nomad "$@"
elif nomad --help "$1" 2>&1 | grep -q "nomad $1"; then
# We can't use the return code to check for the existence of a subcommand, so
# we have to use grep to look for a pattern in the help output.
set -- nomad "$@"
fi
# If we are running Nomad, make sure it executes as the proper user.
if [ "$1" = 'nomad' ]; then
# If the data or config dirs are bind mounted then chown them.
# Note: This checks for root ownership as that's the most common case.
if [ "$(stat -c %u /nomad/data)" != "$(id -u nomad)" ]; then
chown nomad:nomad /nomad/data
fi
if [ "$(stat -c %u /nomad/config)" != "$(id -u nomad)" ]; then
chown nomad:nomad /nomad/config
fi
# If requested, set the capability to bind to privileged ports before
# we drop to the non-root user. Note that this doesn't work with all
# storage drivers (it won't work with AUFS).
if [ ! -z ${NOMAD_ALLOW_PRIVILEGED_PORTS+x} ]; then
setcap "cap_net_bind_service=+ep" /bin/nomad
fi
set -- su-exec nomad:nomad "$@"
fi
exec "$@"