Skip to content

Commit e8ff00b

Browse files
committed
Improve entrypoint logic
1 parent 4f7064c commit e8ff00b

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

or-entrypoint.sh

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,14 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
4545
echo "---------------------------------------------------------------------------------------"
4646
echo "Existing postgresql.conf found checking for shared_preload_libraries = 'timescaledb'..."
4747
echo "---------------------------------------------------------------------------------------"
48-
RESULT=$(cat "$PGDATA/postgresql.conf" | grep "^shared_preload_libraries = 'timescaledb'" || true)
4948

50-
if [ -n "$RESULT" ]; then
51-
echo "-------------------------------------------"
52-
echo "Timescale DB library already set to preload"
53-
echo "-------------------------------------------"
49+
# Check if timescaledb is already in the config (anywhere in the line)
50+
if grep -q "^shared_preload_libraries.*timescaledb" "$PGDATA/postgresql.conf"; then
51+
echo "Timescale DB library already present in shared_preload_libraries"
5452
else
55-
echo "------------------------------------------------------------------"
56-
echo "Adding shared_preload_libraries = 'timescaledb' to postgresql.conf"
57-
echo "------------------------------------------------------------------"
58-
echo "shared_preload_libraries = 'timescaledb'" >> "$PGDATA/postgresql.conf"
59-
echo "timescaledb.telemetry_level=off" >> "$PGDATA/postgresql.conf"
53+
echo "Adding timescaledb to shared_preload_libraries..."
54+
echo "shared_preload_libraries = 'timescaledb'" >> "$PGDATA/postgresql.conf"
55+
echo "timescaledb.telemetry_level=off" >> "$PGDATA/postgresql.conf"
6056
fi
6157

6258
########################################################################################
@@ -352,34 +348,34 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
352348
echo "Copying the old pg_hba and pg_ident configuration files is complete"
353349
echo "-------------------------------------------------------------------"
354350

355-
# Don't automatically abort on non-0 exit status
356-
set +e
357-
358-
# Copy any reindex counter files
351+
# Copy reindex/version files
359352
echo "--------------------------------------------------------------"
360353
echo "Copying reindex and TS version files across"
361354
echo "--------------------------------------------------------------"
362-
cp -f ${OLD}/OR_REINDEX_* ${PGDATA}
363-
cp -f ${OLD}/OR_TS_VERSION ${PGDATA}
355+
cp -f "${OLD}/OR_REINDEX_*" "${PGDATA}" || true
356+
cp -f "${OLD}/OR_TS_VERSION" "${PGDATA}" || true
364357
echo "-------------------------------------------------------------------"
365-
echo "Copying reindex files is complete"
358+
echo "Copying reindex and TS version files is complete"
366359
echo "-------------------------------------------------------------------"
367-
360+
368361
# Remove the left over database files
369362
echo "---------------------------------"
370363
echo "Removing left over database files"
371364
echo "---------------------------------"
372-
rm -rf "${OLD}" "${NEW}" delete_old_cluster.sh
365+
# Ensure we are actually in the right place and New Data exists before deleting Old
366+
if [ -d "${PGDATA}/base" ]; then
367+
rm -rf "${OLD}" "${NEW}" delete_old_cluster.sh
368+
else
369+
echo "CRITICAL ERROR: Data directory appears empty. Refusing to delete backup ${OLD}"
370+
exit 1
371+
fi
373372
echo "---------------------------------------------"
374373
echo "Removing left over database files is complete"
375374
echo "---------------------------------------------"
376375

377376
echo "================================================================================="
378377
echo "STEP 2 Complete: PostgreSQL upgraded from ${DB_VERSION} to ${PG_MAJOR}"
379378
echo "================================================================================="
380-
381-
# Return the error handling back to automatically aborting on non-0 exit status
382-
set -e
383379
fi
384380

385381
# If we just did a PostgreSQL upgrade, we MUST upgrade TimescaleDB on the new cluster
@@ -481,7 +477,7 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
481477
echo "REINDEX completed!"
482478
touch "$REINDEX_FILE"
483479

484-
echo "Stoppig temporary server..."
480+
echo "Stopping temporary server..."
485481
docker_temp_server_stop
486482
fi
487483
fi

0 commit comments

Comments
 (0)