Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: changed opensearch startup to turn opensearch into main process (#1326)

Lucas Oliveira87dfd2d84951
diff --git a/Dockerfile b/Dockerfile
index ed9811d31..e4e532514 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -122,6 +122,11 @@ RUN echo '#!/bin/bash' > /usr/share/opensearch/setup-security.sh && \
echo 'echo "Security configuration applied successfully"' >> /usr/share/opensearch/setup-security.sh && \
chmod +x /usr/share/opensearch/setup-security.sh
+# Copy custom entrypoint wrapper that handles graceful shutdown
+COPY opensearch-entrypoint-wrapper.sh /usr/share/opensearch/
+RUN chmod +x /usr/share/opensearch/opensearch-entrypoint-wrapper.sh && \
+ chown opensearch:opensearch /usr/share/opensearch/opensearch-entrypoint-wrapper.sh
+
########################################
# Final runtime settings
########################################
@@ -133,6 +138,6 @@ ENV PATH=$PATH:$JAVA_HOME/bin:$OPENSEARCH_HOME/bin
# Expose ports
EXPOSE 9200 9300 9600 9650
-ENTRYPOINT ["./opensearch-docker-entrypoint.sh"]
-CMD ["opensearch"]
+ENTRYPOINT ["./opensearch-entrypoint-wrapper.sh"]
+CMD []
diff --git a/docker-compose.yml b/docker-compose.yml
index add0377ae..fd024e88a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,26 +10,20 @@ services:
environment:
- discovery.type=single-node
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}
- # Run security setup in background after OpenSearch starts
- command: >
- bash -c "
- # Ensure data directory has correct permissions
- sudo chown -R opensearch:opensearch /usr/share/opensearch/data || true
-
- # Start OpenSearch in background
- /usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch &
-
- # Wait a bit for OpenSearch to start, then apply security config
- sleep 10 && /usr/share/opensearch/setup-security.sh &
-
- # Wait for background processes
- wait
- "
+ - OPENSEARCH_JAVA_OPTS=-Xms1g -Xmx1g
ports:
- "9200:9200"
- "9600:9600"
volumes:
- - ${OPENSEARCH_DATA_PATH:-./opensearch-data}:/usr/share/opensearch/data:U,z
+ - opensearch-data:/usr/share/opensearch/data
+ stop_grace_period: 2m
+ healthcheck:
+ test: ["CMD-SHELL", "curl -ku admin:$$OPENSEARCH_PASSWORD 'https://localhost:9200/_cluster/health' -s | grep -qE '\"status\":\"(green|yellow)\"'"]
+ interval: 15s
+ timeout: 10s
+ retries: 20
+ start_period: 60s
+ restart: unless-stopped
dashboards:
image: opensearchproject/opensearch-dashboards:3.0.0
@@ -189,3 +183,6 @@ services:
- LANGFLOW_ENABLE_SUPERUSER_CLI=${LANGFLOW_ENABLE_SUPERUSER_CLI}
# - DEFAULT_FOLDER_NAME=OpenRAG
- HIDE_GETTING_STARTED_PROGRESS=true
+
+volumes:
+ opensearch-data:
diff --git a/opensearch-entrypoint-wrapper.sh b/opensearch-entrypoint-wrapper.sh
new file mode 100644
index 000000000..dcf6f8381
--- /dev/null
+++ b/opensearch-entrypoint-wrapper.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+set -e
+
+# Start OpenSearch in the background
+/usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch &
+OPENSEARCH_PID=$!
+
+# Function to handle shutdown signals
+shutdown() {
+ echo "Received shutdown signal, stopping OpenSearch gracefully..."
+ kill -TERM "$OPENSEARCH_PID" 2>/dev/null || true
+ # Wait up to 90s for graceful stop, then force-kill
+ for i in $(seq 1 90); do
+ kill -0 "$OPENSEARCH_PID" 2>/dev/null || break
+ sleep 1
+ done
+ kill -KILL "$OPENSEARCH_PID" 2>/dev/null || true
+ wait "$OPENSEARCH_PID"
+ echo "OpenSearch stopped"
+ exit 0
+}
+
+# Trap shutdown signals
+trap shutdown SIGTERM SIGINT
+
+# Run security setup in background after a delay
+(
+ sleep 15
+ echo "Running security setup..."
+ /usr/share/opensearch/setup-security.sh || echo "Security setup failed or already configured"
+) &
+
+# Wait for OpenSearch process
+wait "$OPENSEARCH_PID"
+