This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocker-entrypoint.sh
executable file
·488 lines (376 loc) · 22.6 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#!/usr/bin/env bash
# SC2155: Declare and assign separately to avoid masking return values.
# shellcheck disable=SC2155
set -Eeo pipefail
# Inspired by: https://github.com/docker-library/postgres/blob/ba30220/13/docker-entrypoint.sh
########
# check to see if this file is being run or sourced from another script
_is_sourced() {
# https://unix.stackexchange.com/a/215279
[ "${#FUNCNAME[@]}" -ge 2 ] \
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
&& [ "${FUNCNAME[1]}" = 'source' ]
}
_main() {
SELF="$( basename "$0" )"
########
# Match first argument to this script.
# Example: "remco" for a full command like "docker-entrypoint.sh remco -config /etc/remco/config",
# or "catalina.sh" for a full command of "docker-entrypoint.sh dhis2-init.sh"
if [ "$1" = 'remco' ] || [ "$1" = 'dhis2-init.sh' ]; then
# Set DHIS2 build information (logic also used in 20_dhis2-initwar.sh):
DHIS2_BUILD_PROPERTIES="$( unzip -q -p "$( find /usr/local/tomcat/webapps/ROOT/WEB-INF/lib -maxdepth 1 -type f -name 'dhis-service-core-[0-9]*.jar' )" build.properties )"
export DHIS2_BUILD_VERSION="$( awk -F'=' '/^build\.version/ {gsub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )"
export DHIS2_BUILD_MAJOR="$( cut -c1-4 <<< "$DHIS2_BUILD_VERSION" )"
export DHIS2_BUILD_REVISION="$( awk -F'=' '/^build\.revision/ {gsub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )"
export DHIS2_BUILD_TIME="$( awk -F'=' '/^build\.time/ {sub(/ /, "", $NF); print $NF}' <<< "$DHIS2_BUILD_PROPERTIES" )"
export DHIS2_BUILD_DATE="$( grep --only-matching --extended-regexp '20[0-9]{2}-[0-9]{2}-[0-9]{2}' <<< "$DHIS2_BUILD_TIME" )"
# Set environment variables for using remco to generate dhis.conf:
# Set contents of DHIS2_DATABASE_PASSWORD_FILE to DHIS2_DATABASE_PASSWORD
if [ -z "${DHIS2_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_DATABASE_PASSWORD="$(<"${DHIS2_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_DATABASE_PASSWORD from DHIS2_DATABASE_PASSWORD_FILE" >&2
fi
# Set contents of DHIS2_REDIS_PASSWORD_FILE to DHIS2_REDIS_PASSWORD
if [ -z "${DHIS2_REDIS_PASSWORD:-}" ] && [ -r "${DHIS2_REDIS_PASSWORD_FILE:-}" ]; then
export DHIS2_REDIS_PASSWORD="$(<"${DHIS2_REDIS_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_REDIS_PASSWORD from DHIS2_REDIS_PASSWORD_FILE" >&2
fi
# Set SYSTEM_IP to the internal IP address
if [ -z "${SYSTEM_IP:-}" ]; then
export SYSTEM_IP="$(hostname --ip-address)"
echo "[DEBUG] $SELF: set SYSTEM_IP=$SYSTEM_IP" >&2
fi
# Set DHIS2_SERVER_BASE_URL if not set to value of DHIS2_SERVER_BASEURL if set
# NOTE: DHIS2_SERVER_BASEURL and this block will be removed later
if [ -z "${DHIS2_SERVER_BASE_URL:-}" ] && [ -n "${DHIS2_SERVER_BASEURL:-}" ]; then
export DHIS2_SERVER_BASE_URL="$DHIS2_SERVER_BASEURL"
echo "[DEBUG] $SELF: set DHIS2_SERVER_BASE_URL=$DHIS2_SERVER_BASE_URL" >&2
fi
# Set DHIS2_SERVER_HTTPS to "on" if not set and DHIS2_SERVER_BASE_URL begins with "https://"
if [ -z "${DHIS2_SERVER_HTTPS:-}" ] && [[ "${DHIS2_SERVER_BASE_URL:-}" =~ ^https:// ]]; then
export DHIS2_SERVER_HTTPS="on"
echo "[DEBUG] $SELF: set DHIS2_SERVER_HTTPS=$DHIS2_SERVER_HTTPS" >&2
fi
# Set TOMCAT_CONNECTOR_PROXYPORT if not set to value dervied from DHIS2_SERVER_BASE_URL if set
if [ -z "${TOMCAT_CONNECTOR_PROXYPORT:-}" ] && [ -n "${DHIS2_SERVER_BASE_URL:-}" ]; then
export TOMCAT_CONNECTOR_PROXYPORT="$( port-from-url.py "$DHIS2_SERVER_BASE_URL" )"
echo "[DEBUG] $SELF: set TOMCAT_CONNECTOR_PROXYPORT=$TOMCAT_CONNECTOR_PROXYPORT" >&2
fi
# Set TOMCAT_CONNECTOR_SCHEME to "https" if not set and DHIS2_SERVER_BASE_URL begins with "https://"
if [ -z "${TOMCAT_CONNECTOR_SCHEME:-}" ] && [[ "${DHIS2_SERVER_BASE_URL:-}" =~ ^https:// ]]; then
export TOMCAT_CONNECTOR_SCHEME="https"
echo "[DEBUG] $SELF: set TOMCAT_CONNECTOR_SCHEME=$TOMCAT_CONNECTOR_SCHEME" >&2
fi
# Set TOMCAT_CONNECTOR_SECURE to "true" if not set and DHIS2_SERVER_HTTPS is "on"
if [ -z "${TOMCAT_CONNECTOR_SECURE:-}" ] && [ "${DHIS2_SERVER_HTTPS:-}" = "on" ]; then
export TOMCAT_CONNECTOR_SECURE="true"
echo "[DEBUG] $SELF: set TOMCAT_CONNECTOR_SECURE=$TOMCAT_CONNECTOR_SECURE" >&2
fi
# Set DHIS2_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_DATABASE_USERNAME:-}" ]; then
export DHIS2_DATABASE_USERNAME="dhis"
echo "[DEBUG] $SELF: set DHIS2_DATABASE_USERNAME=$DHIS2_DATABASE_USERNAME" >&2
fi
# Set DHIS2_CONNECTION_USERNAME if not provided
if [ -z "${DHIS2_CONNECTION_USERNAME:-}" ]; then
export DHIS2_CONNECTION_USERNAME="$DHIS2_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_USERNAME=$DHIS2_CONNECTION_USERNAME" >&2
fi
# Set DHIS2_CONNECTION_PASSWORD if not provided and DHIS2_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_DATABASE_PASSWORD:-}" ]; then
export DHIS2_CONNECTION_PASSWORD="$DHIS2_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_PASSWORD to the value of DHIS2_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_CONNECTION_URL from DHIS2_DATABASE_* values
if [ -z "${DHIS2_CONNECTION_URL:-}" ]; then
# Set DHIS2_DATABASE_NAME if not provided
if [ -z "${DHIS2_DATABASE_NAME:-}" ]; then
export DHIS2_DATABASE_NAME="dhis2"
echo "[DEBUG] $SELF: set DHIS2_DATABASE_NAME=$DHIS2_DATABASE_NAME" >&2
fi
# Set DHIS2_CONNECTION_URL as a remote URL if DHIS2_DATABASE_HOST is provided
if [ -n "${DHIS2_DATABASE_HOST:-}" ]; then
# Set DHIS2_DATABASE_PORT if not provided
if [ -z "${DHIS2_DATABASE_PORT:-}" ]; then
export DHIS2_DATABASE_PORT="5432"
echo "[DEBUG] $SELF: set DHIS2_DATABASE_PORT=$DHIS2_DATABASE_PORT" >&2
fi
export DHIS2_CONNECTION_URL="jdbc:postgresql://$DHIS2_DATABASE_HOST:$DHIS2_DATABASE_PORT/$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_URL=$DHIS2_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_CONNECTION_URL="jdbc:postgresql:$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_URL=$DHIS2_CONNECTION_URL" >&2
fi
fi
# Set DHIS2_CONNECTION_DIALECT if not provided
if [ -z "${DHIS2_CONNECTION_DIALECT:-}" ]; then
export DHIS2_CONNECTION_DIALECT="org.hibernate.dialect.PostgreSQLDialect"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_DIALECT=$DHIS2_CONNECTION_DIALECT" >&2
fi
# Set DHIS2_CONNECTION_DRIVER_CLASS if not provided for DHIS2 2.38 and below
if [ -z "${DHIS2_CONNECTION_DRIVER_CLASS:-}" ] && [ "${DHIS2_BUILD_MAJOR//.}" -le "238" ]; then
export DHIS2_CONNECTION_DRIVER_CLASS="org.postgresql.Driver"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_DRIVER_CLASS=$DHIS2_CONNECTION_DRIVER_CLASS" >&2
fi
# Set DHIS2_CONNECTION_SCHEMA if not provided for DHIS2 2.37 and below
if [ -z "${DHIS2_CONNECTION_SCHEMA:-}" ] && [ "${DHIS2_BUILD_MAJOR//.}" -le "237" ]; then
export DHIS2_CONNECTION_SCHEMA="update"
echo "[DEBUG] $SELF: set DHIS2_CONNECTION_SCHEMA=$DHIS2_CONNECTION_SCHEMA" >&2
fi
# Set DHIS2_NODE_ID as hostname
if [ -z "${DHIS2_NODE_ID:-}" ]; then
export DHIS2_NODE_ID="$(hostname --fqdn)"
echo "[DEBUG] $SELF: set DHIS2_NODE_ID=$DHIS2_NODE_ID" >&2
fi
# Set SYSTEM_FQDN [DEPRECATED] as DHIS2_NODE_ID
if [ -z "${SYSTEM_FQDN:-}" ]; then
export SYSTEM_FQDN="$DHIS2_NODE_ID"
echo "[DEBUG] $SELF: set SYSTEM_FQDN=$SYSTEM_FQDN [DEPRECATED]" >&2
fi
# DHIS2 can support up to 5 read replicas.
# Read replica 1
if [ -z "${DHIS2_READ1_CONNECTION_URL:-}" ] \
&& { [ -n "${DHIS2_READ1_DATABASE_HOST:-}" ] || [ -n "${DHIS2_READ1_DATABASE_NAME:-}" ]; } ; then
# Set DHIS2_READ1_DATABASE_NAME if not provided
if [ -z "${DHIS2_READ1_DATABASE_NAME:-}" ]; then
export DHIS2_READ1_DATABASE_NAME="$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ1_DATABASE_NAME=$DHIS2_READ1_DATABASE_NAME" >&2
fi
# Set DHIS2_READ1_CONNECTION_URL as a remote URL if DHIS2_READ1_DATABASE_HOST is provided
if [ -n "${DHIS2_READ1_DATABASE_HOST:-}" ]; then
# Set DHIS2_READ1_DATABASE_PORT if not provided
if [ -z "${DHIS2_READ1_DATABASE_PORT:-}" ]; then
export DHIS2_READ1_DATABASE_PORT="$DHIS2_DATABASE_PORT"
echo "[DEBUG] $SELF: set DHIS2_READ1_DATABASE_PORT=$DHIS2_READ1_DATABASE_PORT" >&2
fi
export DHIS2_READ1_CONNECTION_URL="jdbc:postgresql://$DHIS2_READ1_DATABASE_HOST:$DHIS2_READ1_DATABASE_PORT/$DHIS2_READ1_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ1_CONNECTION_URL=$DHIS2_READ1_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_READ1_CONNECTION_URL="jdbc:postgresql:$DHIS2_READ1_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ1_CONNECTION_URL=$DHIS2_READ1_CONNECTION_URL" >&2
fi
# Set contents of DHIS2_READ1_DATABASE_PASSWORD_FILE to DHIS2_READ1_DATABASE_PASSWORD
if [ -z "${DHIS2_READ1_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_READ1_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_READ1_DATABASE_PASSWORD="$(<"${DHIS2_READ1_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_READ1_DATABASE_PASSWORD from DHIS2_READ1_DATABASE_PASSWORD_FILE" >&2
fi
# Set DHIS2_READ1_CONNECTION_PASSWORD if not provided and DHIS2_READ1_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_READ1_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_READ1_DATABASE_PASSWORD:-}" ]; then
export DHIS2_READ1_CONNECTION_PASSWORD="$DHIS2_READ1_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_READ1_CONNECTION_PASSWORD to the value of DHIS2_READ1_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_READ1_CONNECTION_USERNAME to DHIS2_READ1_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_READ1_CONNECTION_USERNAME:-}" ] && [ -n "${DHIS2_READ1_DATABASE_USERNAME:-}" ]; then
export DHIS2_READ1_CONNECTION_USERNAME="$DHIS2_READ1_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_READ1_CONNECTION_USERNAME=$DHIS2_READ1_CONNECTION_USERNAME" >&2
fi
fi
# Read replica 2
if [ -z "${DHIS2_READ2_CONNECTION_URL:-}" ] \
&& { [ -n "${DHIS2_READ2_DATABASE_HOST:-}" ] || [ -n "${DHIS2_READ2_DATABASE_NAME:-}" ]; } ; then
# Set DHIS2_READ2_DATABASE_NAME if not provided
if [ -z "${DHIS2_READ2_DATABASE_NAME:-}" ]; then
export DHIS2_READ2_DATABASE_NAME="$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ2_DATABASE_NAME=$DHIS2_READ2_DATABASE_NAME" >&2
fi
# Set DHIS2_READ2_CONNECTION_URL as a remote URL if DHIS2_READ2_DATABASE_HOST is provided
if [ -n "${DHIS2_READ2_DATABASE_HOST:-}" ]; then
# Set DHIS2_READ2_DATABASE_PORT if not provided
if [ -z "${DHIS2_READ2_DATABASE_PORT:-}" ]; then
export DHIS2_READ2_DATABASE_PORT="$DHIS2_DATABASE_PORT"
echo "[DEBUG] $SELF: set DHIS2_READ2_DATABASE_PORT=$DHIS2_READ2_DATABASE_PORT" >&2
fi
export DHIS2_READ2_CONNECTION_URL="jdbc:postgresql://$DHIS2_READ2_DATABASE_HOST:$DHIS2_READ2_DATABASE_PORT/$DHIS2_READ2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ2_CONNECTION_URL=$DHIS2_READ2_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_READ2_CONNECTION_URL="jdbc:postgresql:$DHIS2_READ2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ2_CONNECTION_URL=$DHIS2_READ2_CONNECTION_URL" >&2
fi
# Set contents of DHIS2_READ2_DATABASE_PASSWORD_FILE to DHIS2_READ2_DATABASE_PASSWORD
if [ -z "${DHIS2_READ2_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_READ2_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_READ2_DATABASE_PASSWORD="$(<"${DHIS2_READ2_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_READ2_DATABASE_PASSWORD from DHIS2_READ2_DATABASE_PASSWORD_FILE" >&2
fi
# Set DHIS2_READ2_CONNECTION_PASSWORD if not provided and DHIS2_READ2_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_READ2_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_READ2_DATABASE_PASSWORD:-}" ]; then
export DHIS2_READ2_CONNECTION_PASSWORD="$DHIS2_READ2_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_READ2_CONNECTION_PASSWORD to the value of DHIS2_READ2_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_READ2_CONNECTION_USERNAME to DHIS2_READ2_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_READ2_CONNECTION_USERNAME:-}" ] && [ -n "${DHIS2_READ2_DATABASE_USERNAME:-}" ]; then
export DHIS2_READ2_CONNECTION_USERNAME="$DHIS2_READ2_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_READ2_CONNECTION_USERNAME=$DHIS2_READ2_CONNECTION_USERNAME" >&2
fi
fi
# Read replica 3
if [ -z "${DHIS2_READ3_CONNECTION_URL:-}" ] \
&& { [ -n "${DHIS2_READ3_DATABASE_HOST:-}" ] || [ -n "${DHIS2_READ3_DATABASE_NAME:-}" ]; } ; then
# Set DHIS2_READ3_DATABASE_NAME if not provided
if [ -z "${DHIS2_READ3_DATABASE_NAME:-}" ]; then
export DHIS2_READ3_DATABASE_NAME="$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ3_DATABASE_NAME=$DHIS2_READ3_DATABASE_NAME" >&2
fi
# Set DHIS2_READ3_CONNECTION_URL as a remote URL if DHIS2_READ3_DATABASE_HOST is provided
if [ -n "${DHIS2_READ3_DATABASE_HOST:-}" ]; then
# Set DHIS2_READ3_DATABASE_PORT if not provided
if [ -z "${DHIS2_READ3_DATABASE_PORT:-}" ]; then
export DHIS2_READ3_DATABASE_PORT="$DHIS2_DATABASE_PORT"
echo "[DEBUG] $SELF: set DHIS2_READ3_DATABASE_PORT=$DHIS2_READ3_DATABASE_PORT" >&2
fi
export DHIS2_READ3_CONNECTION_URL="jdbc:postgresql://$DHIS2_READ3_DATABASE_HOST:$DHIS2_READ3_DATABASE_PORT/$DHIS2_READ3_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ3_CONNECTION_URL=$DHIS2_READ3_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_READ3_CONNECTION_URL="jdbc:postgresql:$DHIS2_READ3_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ3_CONNECTION_URL=$DHIS2_READ3_CONNECTION_URL" >&2
fi
# Set contents of DHIS2_READ3_DATABASE_PASSWORD_FILE to DHIS2_READ3_DATABASE_PASSWORD
if [ -z "${DHIS2_READ3_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_READ3_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_READ3_DATABASE_PASSWORD="$(<"${DHIS2_READ3_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_READ3_DATABASE_PASSWORD from DHIS2_READ3_DATABASE_PASSWORD_FILE" >&2
fi
# Set DHIS2_READ3_CONNECTION_PASSWORD if not provided and DHIS2_READ3_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_READ3_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_READ3_DATABASE_PASSWORD:-}" ]; then
export DHIS2_READ3_CONNECTION_PASSWORD="$DHIS2_READ3_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_READ3_CONNECTION_PASSWORD to the value of DHIS2_READ3_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_READ3_CONNECTION_USERNAME to DHIS2_READ3_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_READ3_CONNECTION_USERNAME:-}" ] && [ -n "${DHIS2_READ3_DATABASE_USERNAME:-}" ]; then
export DHIS2_READ3_CONNECTION_USERNAME="$DHIS2_READ3_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_READ3_CONNECTION_USERNAME=$DHIS2_READ3_CONNECTION_USERNAME" >&2
fi
fi
# Read replica 4
if [ -z "${DHIS2_READ4_CONNECTION_URL:-}" ] \
&& { [ -n "${DHIS2_READ4_DATABASE_HOST:-}" ] || [ -n "${DHIS2_READ4_DATABASE_NAME:-}" ]; } ; then
# Set DHIS2_READ4_DATABASE_NAME if not provided
if [ -z "${DHIS2_READ4_DATABASE_NAME:-}" ]; then
export DHIS2_READ4_DATABASE_NAME="$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ4_DATABASE_NAME=$DHIS2_READ4_DATABASE_NAME" >&2
fi
# Set DHIS2_READ4_CONNECTION_URL as a remote URL if DHIS2_READ4_DATABASE_HOST is provided
if [ -n "${DHIS2_READ4_DATABASE_HOST:-}" ]; then
# Set DHIS2_READ4_DATABASE_PORT if not provided
if [ -z "${DHIS2_READ4_DATABASE_PORT:-}" ]; then
export DHIS2_READ4_DATABASE_PORT="$DHIS2_DATABASE_PORT"
echo "[DEBUG] $SELF: set DHIS2_READ4_DATABASE_PORT=$DHIS2_READ4_DATABASE_PORT" >&2
fi
export DHIS2_READ4_CONNECTION_URL="jdbc:postgresql://$DHIS2_READ4_DATABASE_HOST:$DHIS2_READ4_DATABASE_PORT/$DHIS2_READ4_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ4_CONNECTION_URL=$DHIS2_READ4_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_READ4_CONNECTION_URL="jdbc:postgresql:$DHIS2_READ4_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ4_CONNECTION_URL=$DHIS2_READ4_CONNECTION_URL" >&2
fi
# Set contents of DHIS2_READ4_DATABASE_PASSWORD_FILE to DHIS2_READ4_DATABASE_PASSWORD
if [ -z "${DHIS2_READ4_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_READ4_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_READ4_DATABASE_PASSWORD="$(<"${DHIS2_READ4_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_READ4_DATABASE_PASSWORD from DHIS2_READ4_DATABASE_PASSWORD_FILE" >&2
fi
# Set DHIS2_READ4_CONNECTION_PASSWORD if not provided and DHIS2_READ4_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_READ4_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_READ4_DATABASE_PASSWORD:-}" ]; then
export DHIS2_READ4_CONNECTION_PASSWORD="$DHIS2_READ4_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_READ4_CONNECTION_PASSWORD to the value of DHIS2_READ4_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_READ4_CONNECTION_USERNAME to DHIS2_READ4_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_READ4_CONNECTION_USERNAME:-}" ] && [ -n "${DHIS2_READ4_DATABASE_USERNAME:-}" ]; then
export DHIS2_READ4_CONNECTION_USERNAME="$DHIS2_READ4_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_READ4_CONNECTION_USERNAME=$DHIS2_READ4_CONNECTION_USERNAME" >&2
fi
fi
# Read replica 5
if [ -z "${DHIS2_READ5_CONNECTION_URL:-}" ] \
&& { [ -n "${DHIS2_READ5_DATABASE_HOST:-}" ] || [ -n "${DHIS2_READ5_DATABASE_NAME:-}" ]; } ; then
# Set DHIS2_READ5_DATABASE_NAME if not provided
if [ -z "${DHIS2_READ5_DATABASE_NAME:-}" ]; then
export DHIS2_READ5_DATABASE_NAME="$DHIS2_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ5_DATABASE_NAME=$DHIS2_READ5_DATABASE_NAME" >&2
fi
# Set DHIS2_READ5_CONNECTION_URL as a remote URL if DHIS2_READ5_DATABASE_HOST is provided
if [ -n "${DHIS2_READ5_DATABASE_HOST:-}" ]; then
# Set DHIS2_READ5_DATABASE_PORT if not provided
if [ -z "${DHIS2_READ5_DATABASE_PORT:-}" ]; then
export DHIS2_READ5_DATABASE_PORT="$DHIS2_DATABASE_PORT"
echo "[DEBUG] $SELF: set DHIS2_READ5_DATABASE_PORT=$DHIS2_READ5_DATABASE_PORT" >&2
fi
export DHIS2_READ5_CONNECTION_URL="jdbc:postgresql://$DHIS2_READ5_DATABASE_HOST:$DHIS2_READ5_DATABASE_PORT/$DHIS2_READ5_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ5_CONNECTION_URL=$DHIS2_READ5_CONNECTION_URL" >&2
# Otherwise, use a local connection
else
export DHIS2_READ5_CONNECTION_URL="jdbc:postgresql:$DHIS2_READ5_DATABASE_NAME"
echo "[DEBUG] $SELF: set DHIS2_READ5_CONNECTION_URL=$DHIS2_READ5_CONNECTION_URL" >&2
fi
# Set contents of DHIS2_READ5_DATABASE_PASSWORD_FILE to DHIS2_READ5_DATABASE_PASSWORD
if [ -z "${DHIS2_READ5_DATABASE_PASSWORD:-}" ] && [ -r "${DHIS2_READ5_DATABASE_PASSWORD_FILE:-}" ]; then
export DHIS2_READ5_DATABASE_PASSWORD="$(<"${DHIS2_READ5_DATABASE_PASSWORD_FILE}")"
echo "[DEBUG] $SELF: set DHIS2_READ5_DATABASE_PASSWORD from DHIS2_READ5_DATABASE_PASSWORD_FILE" >&2
fi
# Set DHIS2_READ5_CONNECTION_PASSWORD if not provided and DHIS2_READ5_DATABASE_PASSWORD is provided
if [ -z "${DHIS2_READ5_CONNECTION_PASSWORD:-}" ] && [ -n "${DHIS2_READ5_DATABASE_PASSWORD:-}" ]; then
export DHIS2_READ5_CONNECTION_PASSWORD="$DHIS2_READ5_DATABASE_PASSWORD"
echo "[DEBUG] $SELF: set DHIS2_READ5_CONNECTION_PASSWORD to the value of DHIS2_READ5_DATABASE_PASSWORD" >&2
fi
# Set DHIS2_READ5_CONNECTION_USERNAME to DHIS2_READ5_DATABASE_USERNAME if not provided
if [ -z "${DHIS2_READ5_CONNECTION_USERNAME:-}" ] && [ -n "${DHIS2_READ5_DATABASE_USERNAME:-}" ]; then
export DHIS2_READ5_CONNECTION_USERNAME="$DHIS2_READ5_DATABASE_USERNAME"
echo "[DEBUG] $SELF: set DHIS2_READ5_CONNECTION_USERNAME=$DHIS2_READ5_CONNECTION_USERNAME" >&2
fi
fi
########
# Steps to perform if the running user is root:
if [ "$(id -u)" = '0' ]; then
if [ "${DISABLE_TOMCAT_TEMPLATES:-}" != '1' ]; then
# Configure tomcat server.xml as root as a "onetime" remco action.
remco -config /etc/remco/tomcat.toml
fi
fi
fi
########
# Match first argument to this script.
# Example: "remco" for a full command of "docker-entrypoint.sh remco -config /etc/remco/config",
# or "catalina.sh" for a full command of "docker-entrypoint.sh dhis2-init.sh",
# or "catalina.sh" for a full command of "docker-entrypoint.sh catalina.sh run -security"
if [ "$1" = 'remco' ] || [ "$1" = 'dhis2-init.sh' ] || [ "$1" = 'catalina.sh' ]; then
# Steps to perform if the running user is root:
if [ "$(id -u)" = '0' ]; then
# Ensure the tomcat user can write to Tomcat and DHIS2 directories
for TOMCAT_DIR in /usr/local/tomcat/{conf/Catalina,logs,temp,work} /opt/dhis2/{files,logs} ; do
if [ -d "$TOMCAT_DIR" ]; then
echo "[DEBUG] $SELF: test if \"tomcat\" user can write to \"$TOMCAT_DIR\"" >&2
if ! gosu tomcat touch "$TOMCAT_DIR/.writable" ; then
echo "[DEBUG] $SELF: setting ownership and permissions on \"$TOMCAT_DIR\"" >&2
chmod --changes u=rwX "$TOMCAT_DIR"
chown --changes tomcat "$TOMCAT_DIR"
if ! gosu tomcat touch "$TOMCAT_DIR/.writable" ; then
echo "[ERROR] $SELF: user \"tomcat\" unable to write to \"$TOMCAT_DIR\", exiting..." >&2
exit 1
fi
fi
rm --interactive=never "$TOMCAT_DIR/.writable"
fi
done
fi
fi
########
# Match first argument to this script.
# Example: "remco" for a full command of "docker-entrypoint.sh remco -config /etc/remco/config",
# or "catalina.sh" for a full command of "docker-entrypoint.sh catalina.sh run -security"
if [ "$1" = 'remco' ] || [ "$1" = 'catalina.sh' ]; then
# Steps to perform if the running user is root:
if [ "$(id -u)" = '0' ]; then
# Run the arguments of this script as a command as the tomcat user.
# NOTE: The script will not continue beyond this point.
exec gosu tomcat "$@"
fi
fi
# Run the arguments of this script as a command.
# NOTE: The script will not continue beyond this point.
exec "$@"
}
if ! _is_sourced; then
_main "$@"
fi