From 93ecdb789e55f4e9c009b8fd190adbd0a599d634 Mon Sep 17 00:00:00 2001 From: ai-dev Date: Mon, 22 Sep 2025 00:16:21 +0200 Subject: [PATCH] test --- .../rootfs/usr/bin/configure-opensearch | 124 +++++++++++++++++- 1 file changed, 120 insertions(+), 4 deletions(-) diff --git a/opensearch-master/rootfs/usr/bin/configure-opensearch b/opensearch-master/rootfs/usr/bin/configure-opensearch index dde2964..6314363 100644 --- a/opensearch-master/rootfs/usr/bin/configure-opensearch +++ b/opensearch-master/rootfs/usr/bin/configure-opensearch @@ -39,16 +39,113 @@ ADMIN_PASSWORD=$(read_config 'admin_password') export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${ADMIN_PASSWORD}" export DISCOVERY_TYPE="multi-node" -# Set heap size using environment variable (better approach) +# Set heap size using environment variable CLEAN_HEAP_SIZE=$(echo "$HEAP_SIZE" | tr -d ' ' | grep -oE '[0-9]+[mg]') if [ -z "$CLEAN_HEAP_SIZE" ]; then CLEAN_HEAP_SIZE="2g" fi export OPENSEARCH_JAVA_OPTS="-Xms${CLEAN_HEAP_SIZE} -Xmx${CLEAN_HEAP_SIZE}" -# 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 +# Create jvm.options directory if it doesn't exist +mkdir -p /usr/share/opensearch/config/jvm.options.d + +# Create or restore the main jvm.options file if it's missing +if [ ! -f "/usr/share/opensearch/config/jvm.options" ]; then + # Create a basic jvm.options file + cat > /usr/share/opensearch/config/jvm.options << 'EOF' +## JVM configuration + +################################################################ +## IMPORTANT: JVM heap size +################################################################ +## +## You should always set the min and max JVM heap +## size to the same value. For example, to set +## the heap to 4 GB, set: +## +## -Xms4g +## -Xmx4g +## +## See https://opensearch.org/docs/latest/opensearch/install/important-settings/ +## for more information +## +################################################################ + +# Xms represents the initial size of total heap space +# Xmx represents the maximum size of total heap space + +-Xms2g +-Xmx2g + +################################################################ +## Expert settings +################################################################ +## +## All settings below this section are considered +## expert settings. Don't tamper with them unless +## you understand what you are doing +## +################################################################ + +## GC configuration +-XX:+UseConcMarkSweepGC +-XX:CMSInitiatingOccupancyFraction=75 +-XX:+UseCMSInitiatingOccupancyOnly + +## optimizations + +# disable calls to System#gc +-XX:+DisableExplicitGC + +# pre-touch memory pages used by the JVM during initialization +-XX:+AlwaysPreTouch + +## basic + +# force the server VM (remove on 32-bit client JVMs) +-server + +# explicitly set the stack size +-Xss1m + +# set to headless, just in case +-Djava.awt.headless=true + +# ensure UTF-8 encoding by default (e.g. filenames) +-Dfile.encoding=UTF-8 + +# use our provided JNA always versus the system one +-Djna.nosys=true + +# turn off a JDK optimization that throws away stack traces for common +# exceptions because stack traces are important for debugging +-XX:-OmitStackTraceInFastThrow + +# flags to configure Netty +-Dio.netty.noUnsafe=true +-Dio.netty.noKeySetOptimization=true +-Dio.netty.recycler.maxCapacityPerThread=0 + +# log4j 2 +-Dlog4j.shutdownHookEnabled=false +-Dlog4j2.disable.jmx=true + +# enable JDK 9+ usage and allow the use of the bundle JDK +--add-opens=java.base/java.io=ALL-UNNAMED +-Des.netty.tryReflectionSetAccessible=true + +-Djava.locale.providers=COMPAT + +# enable the module path +--module-path=${OPENSEARCH_HOME}/lib/* + +# allow access to the jdk.unsupported module for sun.misc.Unsafe +--add-modules=jdk.unsupported + +# allow access to the jdk.incubator.vector module for VectorUtil +--add-modules=jdk.incubator.vector +EOF +fi # Export variables for envsubst export CLUSTER_NAME="${CLUSTER_NAME:-hass-opensearch-cluster}" @@ -75,5 +172,24 @@ if [ -n "$PLUGINS_JSON" ] && [ "$PLUGINS_JSON" != "[]" ] && command -v bashio >/ fi fi +# Try to set vm.max_map_count if we have privileges +if [ -w /proc/sys/vm/max_map_count ]; then + echo "Setting vm.max_map_count to 262144" + echo 262144 > /proc/sys/vm/max_map_count +elif command -v sysctl >/dev/null 2>&1; then + echo "Trying to set vm.max_map_count with sysctl" + sysctl -w vm.max_map_count=262144 || true +fi + +# Check current value +if [ -r /proc/sys/vm/max_map_count ]; then + CURRENT_MAP_COUNT=$(cat /proc/sys/vm/max_map_count) + echo "Current vm.max_map_count: $CURRENT_MAP_COUNT" + if [ "$CURRENT_MAP_COUNT" -lt 262144 ]; then + echo "WARNING: vm.max_map_count is too low ($CURRENT_MAP_COUNT), should be at least 262144" + echo "You may need to run: sudo sysctl -w vm.max_map_count=262144 on the host system" + fi +fi + # Start OpenSearch exec /usr/share/opensearch/bin/opensearch \ No newline at end of file