update opensearch master

This commit is contained in:
ai-dev
2025-10-11 20:25:46 +02:00
parent 4957b52f3a
commit 3a4776bae0
7 changed files with 88 additions and 234 deletions

View File

@@ -0,0 +1,30 @@
#!/usr/bin/with-contenv bash
# Set environment variables
export OPENSEARCH_HOME="/usr/share/opensearch"
export OPENSEARCH_PATH_CONF="/etc/opensearch"
export OPENSEARCH_JAVA_OPTS="-Xms${HEAP_SIZE:-2g} -Xmx${HEAP_SIZE:-2g}"
# Create config directory
mkdir -p /etc/opensearch
# Generate opensearch.yml
cat > /etc/opensearch/opensearch.yml << EOF
cluster.name: ${CLUSTER_NAME:-home-assistant-cluster}
node.name: ${NODE_NAME:-opensearch-master}
node.roles: [master]
path.data: /var/lib/opensearch
path.logs: /var/log/opensearch
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: [${DISCOVERY_SEED_HOSTS:-opensearch-master,opensearch-coordinator}]
cluster.initial_master_nodes: [${INITIAL_MASTER_NODES:-opensearch-master,opensearch-coordinator}]
plugins.security.disabled: true
EOF
# Set permissions
chown -R opensearch:opensearch /etc/opensearch /var/lib/opensearch /var/log/opensearch

View File

@@ -1,17 +0,0 @@
cluster.name: "${CLUSTER_NAME}"
node.name: "${NODE_NAME}"
node.roles: [${NODE_ROLE}]
path.data: /usr/share/opensearch/data
path.logs: /usr/share/opensearch/logs
network.host: 0.0.0.0
http.port: ${HTTP_PORT}
transport.port: ${TRANSPORT_PORT}
discovery.seed_hosts: [${DISCOVERY_SEEDS}]
cluster.initial_master_nodes: [${INITIAL_MASTERS}]
plugins.security.disabled: ${SECURITY_ENABLED}
action.auto_create_index: true

View File

@@ -0,0 +1,2 @@
#!/usr/bin/with-contenv bash
exec s6-setuidgid opensearch /usr/share/opensearch/bin/opensearch

View File

@@ -1,74 +0,0 @@
#!/bin/bash
# Function to read configuration using bashio
read_config() {
if command -v bashio >/dev/null 2>&1; then
bashio::config "$1"
else
# Fallback for testing
case "$1" in
"node_role") echo "master" ;;
"cluster_name") echo "hass-opensearch-cluster" ;;
"node_name") echo "os-master" ;;
"heap_size") echo "1g" ;;
"http_port") echo "9200" ;;
"transport_port") echo "9300" ;;
"discovery_seed_hosts") echo '["os-master:9300"]' ;;
"initial_master_nodes") echo '["os-master"]' ;;
"security_enabled") echo "false" ;;
"admin_password") echo "SecurePass123!" ;;
"plugins") echo "[]" ;;
*) echo "" ;;
esac
fi
}
# Read configuration
NODE_ROLE=$(read_config 'node_role' | tr -d '[]"' | tr ',' ' ')
CLUSTER_NAME=$(read_config 'cluster_name')
NODE_NAME=$(read_config 'node_name')
HEAP_SIZE=$(read_config 'heap_size')
HTTP_PORT=$(read_config 'http_port')
TRANSPORT_PORT=$(read_config 'transport_port')
DISCOVERY_SEEDS=$(read_config 'discovery_seed_hosts' | tr -d '[]"' | tr ',' ' ')
INITIAL_MASTERS=$(read_config 'initial_master_nodes' | tr -d '[]"' | tr ',' ' ')
SECURITY_ENABLED=$(read_config 'security_enabled')
ADMIN_PASSWORD=$(read_config 'admin_password')
# Set heap size
export OPENSEARCH_JAVA_OPTS="-Xms${HEAP_SIZE} -Xmx${HEAP_SIZE}"
export OPENSEARCH_HEAP_SIZE="${HEAP_SIZE}"
# Set admin password
export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${ADMIN_PASSWORD}"
# Export variables for envsubst
export CLUSTER_NAME="${CLUSTER_NAME:-hass-opensearch-cluster}"
export NODE_NAME="${NODE_NAME:-os-master}"
export NODE_ROLE="${NODE_ROLE:-master}"
export HTTP_PORT="${HTTP_PORT:-9200}"
export TRANSPORT_PORT="${TRANSPORT_PORT:-9300}"
export DISCOVERY_SEEDS="${DISCOVERY_SEEDS:-os-master:9300}"
export INITIAL_MASTERS="${INITIAL_MASTERS:-os-master}"
export SECURITY_ENABLED="${SECURITY_ENABLED:-false}"
# Generate configuration from template
envsubst < /etc/opensearch/opensearch.yml.template > /usr/share/opensearch/config/opensearch.yml
# Install plugins if specified
PLUGINS_JSON=$(read_config 'plugins')
if [ -n "$PLUGINS_JSON" ] && [ "$PLUGINS_JSON" != "[]" ]; then
PLUGINS=$(echo "$PLUGINS_JSON" | jq -r '.[]' 2>/dev/null || echo "")
for plugin in $PLUGINS; do
echo "Installing plugin: $plugin"
/usr/share/opensearch/bin/opensearch-plugin install --batch "$plugin" || true
done
fi
# Set vm.max_map_count if possible
if [ -w /proc/sys/vm/max_map_count ]; then
echo 262144 > /proc/sys/vm/max_map_count
fi
# Start OpenSearch as opensearch user
exec su-exec opensearch /usr/share/opensearch/bin/opensearch