Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Some notes:
- Use option `--deploy-path` to run the container with a deploy path namespace (i.e: `--deploy-path=dhis2` serves `http://localhost:8080/dhis2`)
- Use option `-k`/`--keep-containers` to re-use existing docker containers, so data from the previous run will be kept.
- Use option `-auth` to pass the instance authentication (`USER:PASS`). It will be used to call post-tomcat scripts.
- Use option `--run-sql=DIRECTORY` to run SQL files (.sql, .sql.gz or .dump files) after the DB has been initialized.
- Use option `--run-sql=DIRECTORY` to run SQL files (.sql, .sql.gz or .dump files) after the DB has been initialized. SQL files containing "strict" in their name will cause `d2-docker start` to stop if an error occurs.
- Use option `--run-scripts=DIRECTORY` to run shell scripts (.sh) from a directory within the `dhis2-core` container. By default, a script is run **after** postgres starts (`host=db`, `port=5432`) but **before** Tomcat starts; if its filename starts with prefix "post", it will be run **after** Tomcat is available. `curl` and typical shell tools are available on that Alpine Linux environment. Note that the Dhis2 endpoint is always `http://localhost:8080/${deployPath}`, regardless of the public port that the instance is exposed to.
- Use option `--java-opts="JAVA_OPTS"` to override the default JAVA_OPTS for the Tomcat process. That's tipically used to set the maximum/initial Heap Memory size (for example: `--java-opts="-Xmx3500m -Xms2500m"`)
- Use option `--postgis-version=13-3.1-alpine` to specify the PostGIS version to use. By default, 10-2.5-alpine is used.
Expand Down
24 changes: 21 additions & 3 deletions src/d2_docker/config/dhis2-core-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export PGPASSWORD="dhis"

dhis2_url="http://localhost:8080/$DEPLOY_PATH"
dhis2_url_with_auth="http://$DHIS2_AUTH@localhost:8080/$DEPLOY_PATH"
psql_cmd="psql -v ON_ERROR_STOP=0 --quiet -h db -U dhis dhis2"
psql_base_cmd="psql --quiet -h db -U dhis dhis2"
psql_cmd="$psql_base_cmd -v ON_ERROR_STOP=0"
psql_strict_cmd="$psql_base_cmd -v ON_ERROR_STOP=1"
pgrestore_cmd="pg_restore -h db -U dhis -d dhis2"
configdir="/config"
homedir="/dhis2-home-files"
Expand Down Expand Up @@ -54,10 +56,26 @@ run_sql_files() {
find "$base_db_path" -type f \( -name '*.sql' \) |
sort | while read -r path; do
echo "Load SQL: $path"
$psql_cmd <"$path" || true
exit_code=0
run_psql_cmd "$path" || exit_code=$?
if [ "$exit_code" -gt 0 ]; then
echo "Exit code: $exit_code"
exit "$exit_code"
fi
done
}

run_psql_cmd() {
local path=$1
if [[ "$path" == *strict* ]]; then
echo "Strict mode: $path"
$psql_strict_cmd < "$path"
else
echo "Normal mode: $path"
$psql_cmd < "$path"
fi
}

run_pre_scripts() {
find "$scripts_dir" -type f -name '*.sh' ! \( -name 'post*' \) | sort | while read -r path; do
debug "Run pre-tomcat script: $path"
Expand Down Expand Up @@ -154,7 +172,7 @@ run() {
else
debug "Container: clean. Load DB"
wait_for_postgres
run_sql_files || true
run_sql_files
run_pre_scripts || true
init_done
fi
Expand Down
2 changes: 1 addition & 1 deletion src/d2_docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
DHIS2_AUTH: "${DHIS2_AUTH}"
entrypoint: bash /config/dhis2-core-entrypoint.sh
command: bash /config/dhis2-core-start.sh
restart: unless-stopped
restart: "no"
depends_on:
- "db"
- "data"
Expand Down