From 39a064f10bfb2570739e0a23a250315691a2dfc3 Mon Sep 17 00:00:00 2001 From: Bastien Saidi Date: Tue, 16 Sep 2025 13:07:00 +0100 Subject: [PATCH 1/4] refactor: Extract initialization logic into separate functions for clarity --- docker-entrypoint.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 600f049..fefd4e0 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -36,11 +36,13 @@ for f in /docker-entrypoint-initdb.d/*; do echo done -if [[ ! -f /db/init_done ]]; then +initialize_db_dir() { echo "No database directory. Initializing" touch /db/changes.log mkdir -p /db/diffs +} +setup_cookie_jar() { if [[ "${USE_OAUTH_COOKIE_CLIENT}" = "yes" ]]; then /app/venv/bin/python /app/bin/oauth_cookie_client.py -o /db/cookie.jar -s /secrets/oauth-settings.json --format netscape # necessary to add newline at the end as oauth_cookie_client doesn't do that @@ -50,6 +52,11 @@ if [[ ! -f /db/init_done ]]; then echo "${OVERPASS_COOKIE_JAR_CONTENTS}" >>/db/cookie.jar fi chown -R overpass:overpass /db/cookie.jar /db/changes.log /db/diffs +} + +if [[ ! -f /db/init_done ]]; then + initialize_db_dir + setup_cookie_jar if [[ "$OVERPASS_MODE" = "clone" ]]; then ( From 6b6877630da4df57894c62c7aae3f08e294331ac Mon Sep 17 00:00:00 2001 From: Bastien Saidi Date: Tue, 16 Sep 2025 13:10:04 +0100 Subject: [PATCH 2/4] refactor: Rearrange initialization logic for clarity in entrypoint script --- docker-entrypoint.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fefd4e0..e0a1576 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -54,11 +54,11 @@ setup_cookie_jar() { chown -R overpass:overpass /db/cookie.jar /db/changes.log /db/diffs } -if [[ ! -f /db/init_done ]]; then - initialize_db_dir - setup_cookie_jar - if [[ "$OVERPASS_MODE" = "clone" ]]; then +if [[ "$OVERPASS_MODE" = "clone" ]]; then + if [[ ! -f /db/init_done ]]; then + initialize_db_dir + setup_cookie_jar ( mkdir -p /db/db && /app/bin/download_clone.sh --db-dir=/db/db --source="${OVERPASS_CLONE_SOURCE}" --meta="${OVERPASS_META}" && @@ -76,9 +76,16 @@ if [[ ! -f /db/init_done ]]; then echo "Overpass container initialization complete. Exiting." exit 0 fi + else + echo "Database directory already initialized. Skipping clone." fi +fi - if [[ "$OVERPASS_MODE" = "init" ]]; then +if [[ "$OVERPASS_MODE" = "init" ]]; then + if [[ ! -f /db/init_done ]]; then + initialize_db_dir + setup_cookie_jar + CURL_STATUS_CODE=$(curl -L -b /db/cookie.jar -o /db/planet.osm.bz2 -w "%{http_code}" "${OVERPASS_PLANET_URL}") # try again until it's allowed while [ "$CURL_STATUS_CODE" = "429" ]; do From 0191113ca5c5b91ed3f15e8b83f5dbd0eb730502 Mon Sep 17 00:00:00 2001 From: Bastien Saidi Date: Tue, 16 Sep 2025 13:22:17 +0100 Subject: [PATCH 3/4] fix(entrypoint): honor OVERPASS_STOP_AFTER_INIT when DB already initialized STOP_AFTER_INIT was only applied if init/clone actually created the DB. When /db/init_done already existed, containers in init mode ignored the flag and stayed running. Now the STOP_AFTER_INIT check is evaluated after the init_done guard, so containers exit consistently in init/clone modes regardless of whether the database was freshly created or already present. --- docker-entrypoint.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index e0a1576..b946e40 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -70,14 +70,13 @@ if [[ "$OVERPASS_MODE" = "clone" ]]; then echo "Failed to clone overpass repository" exit 1 ) - if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then - echo "Overpass container ready to receive requests" - else - echo "Overpass container initialization complete. Exiting." - exit 0 - fi + fi + + if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then + echo "Overpass container ready to receive requests" else - echo "Database directory already initialized. Skipping clone." + echo "Overpass container initialization complete. Exiting." + exit 0 fi fi @@ -116,12 +115,6 @@ if [[ "$OVERPASS_MODE" = "init" ]]; then echo "Failed to process planet file" exit 1 ) - if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then - echo "Overpass container ready to receive requests" - else - echo "Overpass container initialization complete. Exiting." - exit 0 - fi elif [[ $CURL_STATUS_CODE = "403" ]]; then echo "Access denied when downloading planet file. Check your OVERPASS_PLANET_URL and OVERPASS_COOKIE_JAR_CONTENTS or USE_OAUTH_COOKIE_CLIENT" cat /db/cookie.jar @@ -132,6 +125,13 @@ if [[ "$OVERPASS_MODE" = "init" ]]; then exit 1 fi fi + + if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then + echo "Overpass container ready to receive requests" + else + echo "Overpass container initialization complete. Exiting." + exit 0 + fi fi # shellcheck disable=SC2016 # ignore SC2016 (variables within single quotes) as this is exactly what we want to do here From 409cdc0177744cec315c060bd5af25e0484f1b43 Mon Sep 17 00:00:00 2001 From: Bastien Saidi Date: Wed, 17 Sep 2025 17:46:53 +0100 Subject: [PATCH 4/4] refactor: simply init logic by consolidating exit conditions --- docker-entrypoint.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b946e40..249efca 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -71,13 +71,6 @@ if [[ "$OVERPASS_MODE" = "clone" ]]; then exit 1 ) fi - - if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then - echo "Overpass container ready to receive requests" - else - echo "Overpass container initialization complete. Exiting." - exit 0 - fi fi if [[ "$OVERPASS_MODE" = "init" ]]; then @@ -125,7 +118,9 @@ if [[ "$OVERPASS_MODE" = "init" ]]; then exit 1 fi fi +fi +if [[ "$OVERPASS_MODE" = "init" || "$OVERPASS_MODE" = "clone" ]]; then if [[ "${OVERPASS_STOP_AFTER_INIT}" == "false" ]]; then echo "Overpass container ready to receive requests" else