From 0438ee880f3247a34a939e75152e21a910055ddf Mon Sep 17 00:00:00 2001 From: Ryan Hodges Date: Mon, 8 Jun 2026 10:37:53 -0700 Subject: [PATCH] preserve harvester's H2 DB across container events --- docker/docker-compose.prod.yml | 2 ++ docker/geoportal-entrypoint.sh | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 8fcf699..5147162 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -98,6 +98,7 @@ services: - 8080:8080 volumes: - gp-volume:/usr/local/tomcat/webapps/ + - harvester_data:/root - ${gpt_catalog_war}:/usr/local/tomcat/webapps/geoportal.war - ${gpt_harvester_war}:/usr/local/tomcat/webapps/harvester.war - ./templates:/templates:ro @@ -177,6 +178,7 @@ volumes: redis_data: gp-volume: es-volume: + harvester_data: networks: madronanetwork: diff --git a/docker/geoportal-entrypoint.sh b/docker/geoportal-entrypoint.sh index cbdc495..692dd88 100755 --- a/docker/geoportal-entrypoint.sh +++ b/docker/geoportal-entrypoint.sh @@ -159,25 +159,22 @@ else echo "✗ app-security.xml missing" fi -# Stop background Tomcat +# Stop background Tomcat gracefully so H2 can flush and release its lock echo "Stopping background Tomcat (PID: $TOMCAT_PID)..." -# Check if the process is still running if kill -0 $TOMCAT_PID 2>/dev/null; then - echo "Sending TERM signal to Tomcat..." - kill $TOMCAT_PID - - # Wait for graceful shutdown (up to 10 seconds) - for i in {1..10}; do + echo "Requesting graceful Tomcat shutdown via catalina.sh stop..." + catalina.sh stop 30 -force + # Wait for the background process to exit + for i in {1..35}; do if ! kill -0 $TOMCAT_PID 2>/dev/null; then echo "Tomcat stopped gracefully" break fi - echo "Waiting for shutdown... ${i}/10" + echo "Waiting for shutdown... ${i}/35" sleep 1 done - - # Force kill if still running + # Final safety net if kill -0 $TOMCAT_PID 2>/dev/null; then echo "Force stopping Tomcat..." kill -9 $TOMCAT_PID @@ -189,6 +186,11 @@ fi echo "Tomcat stopped successfully" +# Remove any stale H2 lock/trace files left by the background Tomcat run. +# These persist in the named volume and prevent the DB from opening on restart. +echo "Cleaning up stale H2 artifacts in /root..." +rm -f /root/harvester.lock.db /root/harvester.trace.db + # Start Tomcat in foreground echo "Starting Tomcat with updated configuration..." exec catalina.sh run \ No newline at end of file