This commit is contained in:
ai-dev
2025-09-22 00:11:50 +02:00
parent cf4f565cce
commit 86ef7be007

View File

@@ -5,7 +5,7 @@ read_config() {
if command -v bashio >/dev/null 2>&1; then
bashio::config "$1"
else
# Fallback for testing outside Home Assistant - return empty to avoid issues
# Fallback for testing outside Home Assistant
case "$1" in
"node_role") echo "master" ;;
"cluster_name") echo "hass-opensearch-cluster" ;;
@@ -39,18 +39,18 @@ ADMIN_PASSWORD=$(read_config 'admin_password')
export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${ADMIN_PASSWORD}"
export DISCOVERY_TYPE="multi-node"
# Set heap size with proper format (remove any extra spaces or invalid characters)
# Set heap size using environment variable (better approach)
CLEAN_HEAP_SIZE=$(echo "$HEAP_SIZE" | tr -d ' ' | grep -oE '[0-9]+[mg]')
if [ -z "$CLEAN_HEAP_SIZE" ]; then
CLEAN_HEAP_SIZE="1g" # Default if invalid
CLEAN_HEAP_SIZE="2g"
fi
export OPENSEARCH_JAVA_OPTS="-Xms${CLEAN_HEAP_SIZE} -Xmx${CLEAN_HEAP_SIZE}"
# Set heap size in jvm.options.d (proper format)
mkdir -p /usr/share/opensearch/config/jvm.options.d
echo "-Xms${CLEAN_HEAP_SIZE}" > /usr/share/opensearch/config/jvm.options.d/heap.options
echo "-Xmx${CLEAN_HEAP_SIZE}" >> /usr/share/opensearch/config/jvm.options.d/heap.options
# Remove any existing heap configuration to avoid duplicates
rm -f /usr/share/opensearch/config/jvm.options.d/heap.options
rm -f /usr/share/opensearch/config/jvm.options
# Export variables for envsubst (ensure they have proper values)
# Export variables for envsubst
export CLUSTER_NAME="${CLUSTER_NAME:-hass-opensearch-cluster}"
export NODE_NAME="${NODE_NAME:-os-node-1}"
export NODE_ROLE="${NODE_ROLE:-master}"
@@ -63,10 +63,9 @@ export SECURITY_ENABLED="${SECURITY_ENABLED:-false}"
# Generate opensearch.yml from template
envsubst < /etc/opensearch/opensearch.yml.template > /usr/share/opensearch/config/opensearch.yml
# Install plugins if specified (only if not in test mode)
# Install plugins if specified
PLUGINS_JSON=$(read_config 'plugins')
if [ -n "$PLUGINS_JSON" ] && [ "$PLUGINS_JSON" != "[]" ] && command -v bashio >/dev/null 2>&1; then
# Extract plugins from JSON array properly
PLUGINS=$(echo "$PLUGINS_JSON" | jq -r '.[]' 2>/dev/null || echo "")
if [ -n "$PLUGINS" ]; then
for plugin in $PLUGINS; do