-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdocker-entrypoint34.sh
executable file
·153 lines (131 loc) · 5.64 KB
/
docker-entrypoint34.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
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
set -e
if [ -z "$ARANGO_INIT_PORT" ] ; then
export ARANGO_INIT_PORT=8999
fi
AUTHENTICATION="true"
export GLIBCXX_FORCE_NEW=1
# if command starts with an option, prepend arangod
case "$1" in
-*) set -- arangod "$@" ;;
*) ;;
esac
if [ "$1" = 'arangod' ]; then
# /var/lib/arangodb3 and /var/lib/arangodb3-apps must exist and
# be writable by the user under which we run the container.
# Make a copy of the configuration file to patch it, note that this
# must work regardless under which user we run:
cp /etc/arangodb3/arangod.conf /tmp/arangod.conf
if [ ! -z "$ARANGO_ENCRYPTION_KEYFILE" ]; then
echo "Using encrypted database"
sed -i /tmp/arangod.conf -e "s;^.*encryption-keyfile.*;encryption-keyfile=$ARANGO_ENCRYPTION_KEYFILE;"
ARANGO_STORAGE_ENGINE=rocksdb
fi
if [ "$ARANGO_STORAGE_ENGINE" == "rocksdb" ]; then
echo "choosing RocksDB storage engine"
sed -i /tmp/arangod.conf -e "s;storage-engine = auto;storage-engine = rocksdb;"
elif [ "$ARANGO_STORAGE_ENGINE" == "mmfiles" ]; then
echo "choosing MMFiles storage engine"
sed -i /tmp/arangod.conf -e "s;storage-engine = auto;storage-engine = mmfiles;"
else
echo "automatically choosing storage engine"
fi
if [ ! -f /var/lib/arangodb3/SERVER ] && [ "$SKIP_DATABASE_INIT" != "1" ]; then
if [ -f "$ARANGO_ROOT_PASSWORD_FILE" ]; then
ARANGO_ROOT_PASSWORD="$(cat $ARANGO_ROOT_PASSWORD_FILE)"
fi
# Please note that the +x in the following line is for the case
# that ARANGO_ROOT_PASSWORD is set but to an empty value, please
# do not remove!
if [ -z "${ARANGO_ROOT_PASSWORD+x}" ] && [ -z "$ARANGO_NO_AUTH" ] && [ -z "$ARANGO_RANDOM_ROOT_PASSWORD" ]; then
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 " You need to specify one of ARANGO_ROOT_PASSWORD, ARANGO_NO_AUTH and ARANGO_RANDOM_ROOT_PASSWORD"
exit 1
fi
if [ ! -z "$ARANGO_RANDOM_ROOT_PASSWORD" ]; then
ARANGO_ROOT_PASSWORD=$(pwgen -s -1 16)
echo "==========================================="
echo "GENERATED ROOT PASSWORD: $ARANGO_ROOT_PASSWORD"
echo "==========================================="
fi
if [ ! -z "${ARANGO_ROOT_PASSWORD+x}" ]; then
echo "Initializing root user...Hang on..."
ARANGODB_DEFAULT_ROOT_PASSWORD="$ARANGO_ROOT_PASSWORD" /usr/sbin/arango-init-database -c /tmp/arangod.conf --server.rest-server false --log.level error --database.init-database true || true
export ARANGO_ROOT_PASSWORD
if [ ! -z "${ARANGO_ROOT_PASSWORD}" ]; then
ARANGOSH_ARGS=" --server.password ${ARANGO_ROOT_PASSWORD} "
fi
else
ARANGOSH_ARGS=" --server.authentication false"
fi
echo "Initializing database...Hang on..."
arangod --config /tmp/arangod.conf \
--server.endpoint tcp://127.0.0.1:$ARANGO_INIT_PORT \
--server.authentication false \
--log.file /tmp/init-log \
--log.foreground-tty false &
pid="$!"
counter=0
ARANGO_UP=0
while [ "$ARANGO_UP" = "0" ]; do
if [ $counter -gt 0 ]; then
sleep 1
fi
if [ "$counter" -gt 100 ]; then
echo "ArangoDB didn't start correctly during init"
cat /tmp/init-log
exit 1
fi
let counter=counter+1
ARANGO_UP=1
arangosh \
--server.endpoint=tcp://127.0.0.1:$ARANGO_INIT_PORT \
--server.authentication false \
--javascript.execute-string "db._version()" \
> /dev/null 2>&1 || ARANGO_UP=0
done
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh)
echo "$0: running $f"
. "$f"
;;
*.js)
echo "$0: running $f"
arangosh ${ARANGOSH_ARGS} \
--server.endpoint=tcp://127.0.0.1:$ARANGO_INIT_PORT \
--javascript.execute "$f"
;;
*/dumps)
echo "$0: restoring databases"
for d in $f/*; do
DBName=$(echo ${d}|sed "s;$f/;;")
echo "restoring $d into ${DBName}";
arangorestore \
${ARANGOSH_ARGS} \
--server.endpoint=tcp://127.0.0.1:$ARANGO_INIT_PORT \
--create-database true \
--include-system-collections true \
--server.database "$DBName" \
--input-directory "$d"
done
echo
;;
esac
done
if ! kill -s TERM "$pid" || ! wait "$pid"; then
echo >&2 'ArangoDB Init failed.'
exit 1
fi
echo "Database initialized...Starting System..."
fi
# if we really want to start arangod and not bash or any other thing
# prepend --authentication as the FIRST argument
# (so it is overridable via command line as well)
shift
if [ ! -z "$ARANGO_NO_AUTH" ]; then
AUTHENTICATION="false"
fi
set -- arangod "$@" --server.authentication="$AUTHENTICATION" --config /tmp/arangod.conf
fi
exec "$@"